【发布时间】:2017-06-13 23:22:00
【问题描述】:
我正在尝试通过按下按钮截取部分屏幕截图并将其保存到相机胶卷。
我有从另一个问题中找到的代码,但按下按钮会使应用程序崩溃。
// Declare the snapshot boundaries
let top: CGFloat = 100
let bottom: CGFloat = 0
// The size of the cropped image
let size = CGSize(width: view.frame.size.width, height: view.frame.size.height - top - bottom)
// Start the context
UIGraphicsBeginImageContext(size)
// we are going to use context in a couple of places
let context = UIGraphicsGetCurrentContext()!
// Transform the context so that anything drawn into it is displaced "top" pixels up
context.translateBy(x: 0, y: -top)
// Draw the view into the context (this is the snapshot)
view.layer.render(in: context)
let snapshot = UIGraphicsGetImageFromCurrentImageContext()
// End the context (this is required to not leak resources)
UIGraphicsEndImageContext()
// Save to photos
UIImageWriteToSavedPhotosAlbum(snapshot!, nil, nil, nil)
【问题讨论】:
-
你调试这段代码是哪一行崩溃了?您是否为按钮正确设置了插座或添加了选择器?
-
能否分享一下崩溃日志。
-
@iasla 问题解决了吗?
-
还没有。我正在研究我的应用程序的其他部分,直到找到解决方案