我试图找出一种方法让我的 iOS 应用程序将屏幕截图保存到相机胶卷,然后弹出警报告诉用户屏幕截图已成功保存。我能想到的唯一方法是使用某种形式的 if/else 循环(正如您将在下面的伪代码注释中看到的那样),但我想不出任何语法可以与 UIKit 中的 UIImageWriteToSavedPhotosAlbum 函数一起使用. 有什么建议么?
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)
}