func screenShotMethod() {
//Create the UIImage
UIGraphicsBeginImageContext(view.frame.size)
view.layer.renderInContext(UIGraphicsGetCurrentContext())
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
//Save it to the camera roll
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
}
我是第一次使用应用程序构建器,我在这里找到了这个代码,它构建成功但是当我按下按钮在模拟器上执行它时,它不会将图像发送到模拟器上的相册,但是它不会发回任何错误消息或崩溃。所以我试图找出如何在我正在构建的应用程序中正常运行此代码?
答案 0 :(得分:-1)
试试这个。你应该添加UIGraphicsBeginImageContextWithOptions
func screenShotMethod() {
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, true, 0.0)
view.layer.renderInContext(UIGraphicsGetCurrentContext())
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
}