【发布时间】:2016-10-22 03:43:54
【问题描述】:
我正在使用以下代码来创建自定义菜单转换。我花了两个小时试图弄清楚为什么快照显示为空白(仅使用 iPhone 7 Plus 模拟器)。但是当我想为这个线程创建一个视频并将其制作成 gif 时,它在我的 iPhone 6S Plus 上运行。
更新:也适用于 iPhone 6S 模拟器。但在 7 Plus 中仍然没有。
import UIKit
class 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
为什么模拟器上的快照是空白的?
【问题讨论】:
-
我已尝试运行该项目,它在 6s 模拟器 (14A345) 上运行良好
-
iPhone 7 Plus sim? 14A345
-
也适用于 6s 模拟器。刚试过。但 7 加,不是
-
This thread 建议这只发生在模拟器中,而不是在真正的 iPhone 7 设备上。
-
对这个案子也很好奇。找到原因了吗?