我正在尝试找到一种方法,让我的iOS应用程序将屏幕截图保存到相机胶卷中,然后弹出一个提示框告诉用户截图已成功保存。我唯一能想到的方法是使用某种形式的if/else循环(如下所示的伪代码注释),但我不知道该如何使用UIKit中的UIImageWriteToSavedPhotosAlbum函数。我在苹果开发网站上看到了建议,说要使用completionSelector和completionTarget,但我不太明白如何使用它们以及在我的代码中应使用哪些特定用语作为completionSelector和completionTarget。我对Swift还比较陌生。有人能解释一下它们是如何工作的,并告诉我如何找到在我的代码中使用它们的语法吗?
func screenshotMethod()
{
UIGraphicsBeginImageContextWithOptions(HighchartsView.scrollView.contentSize, false, 0);
view.layer.renderInContext(UIGraphicsGetCurrentContext())
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
//if saved to Camera Roll
// {
// confirmScreenshot()
// }
//
//else
// {
// exit code/stop
// }
}
func confirmScreenshot()
{
let alertController = UIAlertController(title: "Success", message: "This chart has been successfully saved to your Camera Roll.", preferredStyle: .Alert)
let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alertController.addAction(defaultAction)
presentViewController(alertController, animated: true, completion: nil)
}