我的第一个问题:)最近我更新我的
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 } } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。