以下代码可在我有权访问的所有设备模拟器上运行。但是,一些用户报告了这个问题,这使我认为在某些情况下未调用完成块。我现在不知道。有什么建议吗?
CATransaction.begin()
CATransaction.setCompletionBlock {
self.performSegue(withIdentifier: "ContractViewController", sender: sender.companyJob)
}
self.navigationController?.popViewController(animated: true)
CATransaction.commit()
顺便说一句,我想要实现的是拥有弹出和推送屏幕过渡动画。此时,我愿意接受任何解决方案或解决方法。预先感谢。
文档中的其他文档:
/* Accessors for the "completionBlock" per-thread transaction property. * Once set to a non-nil value the block is guaranteed to be called (on * the main thread) as soon as all animations subsequently added by * this transaction group have completed (or been removed). If no * animations are added before the current transaction group is * committed (or the completion block is set to a different value), the * block will be invoked immediately. Added in Mac OS X 10.6. */
答案 0 :(得分:-1)
如果您使用的是界面生成器,则可以使用Unwind Segue并创建一个带有完成块的自定义UIStoryboardSegue
class ViewController: UIViewController {
@IBAction func unwind(_ segue: UIStoryboardSegue) {
if let segue = segue as? StoryboardSegue {
segue.completion = {
// present or push in here
}
}
}
}
class StoryboardSegue: UIStoryboardSegue {
var completion: (() -> Void)?
override func perform() {
super.perform()
self.destination.transitionCoordinator?.animate(alongsideTransition: { _ in
}, completion: { _ in
// do what you want after the animation is finished
self.completion?()
})
}
}