
更新:适用于iPhone 6S模拟器.但仍然没有在7 Plus.
import UIKitclass PresentMenuAnimator : NSObject {}extension PresentMenuAnimator : UIVIEwControllerAnimatedTransitioning { func TransitionDuration(using TransitionContext: UIVIEwControllerContextTransitioning?) -> TimeInterval { return 0.6 } func animateTransition(using TransitionContext: UIVIEwControllerContextTransitioning) { let fromVC = TransitionContext.vIEwController(forKey: UITransitionContextVIEwControllerKey.from) let toVC = TransitionContext.vIEwController(forKey: UITransitionContextVIEwControllerKey.to) let containerVIEw = TransitionContext.containerVIEw containerVIEw.insertSubvIEw((toVC?.vIEw)!,belowSubvIEw: (fromVC?.vIEw)!) // replace main vIEw with snapshot let snapshot = fromVC?.vIEw.snapshotVIEw(afterScreenUpdates: false) snapshot?.tag = MenuHelper.snapshotNumber snapshot?.isUserInteractionEnabled = false snapshot?.layer.shadowOpacity = 0.7 containerVIEw.insertSubvIEw(snapshot!,aboveSubvIEw: (toVC?.vIEw)!) fromVC?.vIEw.isHIDden = true UIVIEw.animate( withDuration: TransitionDuration(using: TransitionContext),animations: { snapshot!.center.x += UIScreen.main.bounds.wIDth * MenuHelper.menuWIDth },completion: { _ in fromVC?.vIEw.isHIDden = false TransitionContext.completeTransition(!TransitionContext.TransitionWasCancelled) } ) }} iPhone 6S Plus(物理设备)iOS 10
iPhone 7 Plus(模拟器)iOS 10
为什么模拟器上的快照是空白的?
GitHub test project
解决方法 添加此UIVIEw扩展,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 } }} 更新以下代码,
let snapshot = fromVC?.vIEw.snapshotVIEw(afterScreenUpdates: false)
用,
let snapshot = fromVC?.vIEw.snapshotVIEw()
Ref
总结以上是内存溢出为你收集整理的ios – Swift 3 /为什么来自snapshotView的快照在iPhone 7 Plus模拟器中显示为空白?全部内容,希望文章能够帮你解决ios – Swift 3 /为什么来自snapshotView的快照在iPhone 7 Plus模拟器中显示为空白?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)