iPhone 7 / 7plus上的空snapshotView [英] An empty snapshotView on iPhone 7/7plus

查看:121
本文介绍了iPhone 7 / 7plus上的空snapshotView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的第一个问题:)最近我将我的Xcode更新为8,并且 resizableSnapshotView 方法在某些模拟器上无法正常工作。在iOS6 / 10和iPhone6s下的模拟器上,snapshotView适用于所有测试设备,但在iPhone7 / 7p模拟器上它是空的。我认为7 / 7p可能需要一些权限来访问快照,但我不知道它们是什么。

My first question here:) Recently I update my Xcode to 8, and the resizableSnapshotView method doesn't work properly on some simulators. The snapshotView works well on all testing devices with iOS9/10 and simulators under iPhone6s, but it is empty on iPhone7/7p simulators. I think 7/7p may need some authorities for accessing snapshot, but I have no idea what they are.

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创建快照。

Use the following UIView extension to create a snapshot using CoreGraphics.

我可以确认这适用于iPhone 7模拟器。

I can confirm this works on iPhone 7 simulator.

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
        }
    }
}

这篇关于iPhone 7 / 7plus上的空snapshotView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆