【发布时间】:2021-07-29 22:15:08
【问题描述】:
我正在想办法让我的 iOS 应用程序将屏幕截图保存到相机胶卷,然后弹出一个警报,告诉用户屏幕截图已成功保存。
我能想到的唯一方法是使用某种形式的 if/else 循环(正如您将在下面的伪代码 cmets 中看到的那样),但我想不出任何语法可以使用 @来自 UIKit 的 987654321@ 函数。我在 Apple 的开发站点上遇到过使用 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)
}
【问题讨论】:
标签: ios swift uiimage screenshot alert