我的第一个问题是:)最近我将 Xcode 更新到 8,并且resizableSnapshotView
该方法在某些模拟器上无法正常工作。 snapshotView 在所有 iOS9/10 的测试设备和 iPhone6s 下的模拟器上都运行良好,但在 iPhone7/7p 模拟器上却是空的。我认为 7/7p 可能需要一些权限来访问快照,但我不知道它们是什么。
let cell = self.tableView.cellForRow(at: IndexPath(row: 0, section: 0)) as! CalendarCell
var topFrame = cell.frame
topFrame.origin.y = tableView.contentOffset.y
topFrame.size.height -= tableView.contentOffset.y
topSnapshotView = tableView.resizableSnapshotView(from: topFrame, afterScreenUpdates: false, withCapInsets: UIEdgeInsets.zero)
使用以下 UIView 扩展通过 CoreGraphics 创建快照。
我可以确认这在 iPhone 7 模拟器上有效。
public extension UIView {
public func snapshotImage() -> UIImage? {
UIGraphicsBeginImageContextWithOptions(bounds.size, isOpaque, 0)
drawHierarchy(in: bounds, afterScreenUpdates: false)
let snapshotImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return snapshotImage
}
public func snapshotView() -> UIView? {
if let snapshotImage = snapshotImage() {
return UIImageView(image: snapshotImage)
} else {
return nil
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)