snapshotView(afterScreenUpdates:true)返回一个空视图 [英] snapshotView(afterScreenUpdates: true) returns an empty view
问题描述
我想为导航控制器实现自定义推送转换.
I want to implement a custom push-transition for a navigation controller.
我首先实现了 UINavigationControllerDelegate
,在其中我返回了 UIViewControllerAnimatedTransitioning
的对象.
I first implemented the UINavigationControllerDelegate
where I return an Object of UIViewControllerAnimatedTransitioning
.
在这堂课中,我想对目标视图进行快照以对其进行动画处理.但是,对于推送搜索,这是行不通的-快照ist为空.[当我弹出时,我设置了 afterScreenUpdates = false
并且一切正常]
In this class, I want to take a snapshot of the destination view in order to animate it. However, for the push-segue, this doesn't work - the snapshot ist empty. [when I pop back, I set afterScreenUpdates = false
and everything works]
guard let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from),
let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to) else {
return
}
guard let snapshot = toVC.view.snapshotView(afterScreenUpdates: true) else {
return }
// Problem:
// snapshot is an empty view!
推荐答案
我发现有必要在推送过渡之后和截屏之前引入一小段延迟,例如十分之一秒.避免空白的屏幕截图.可能这会使界面以某种方式稳定下来.
I find that it is necessary to introduce a short delay, say about a tenth of a second, after the push transition and before taking the screenshot, in order to avoid the blank screenshot. Probably this lets the interface settle down in some way.
这篇关于snapshotView(afterScreenUpdates:true)返回一个空视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!