快速 UIView 动画完成处理程序首先调用



我找到了一个不错的卷曲视图动画,我想在完成后添加 segue,但 segue 首先调用(即使返回视图控制器我也可以看到动画结束(。请帮助我找到错误或实现目标的方法

UIView.animate(withDuration: 1, animations: {
let animation = CATransition()
animation.duration = 1
animation.startProgress = 0.0
animation.endProgress = 1
animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
animation.type = CATransitionType(rawValue: "pageCurl")
animation.subtype = CATransitionSubtype(rawValue: "fromRight")
animation.isRemovedOnCompletion = false
animation.isRemovedOnCompletion = false
self.selectedCell!.view1.layer.add(animation, forKey: "pageFlipAnimation")
}, completion: { _ in
let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "PageVC") as? PageVC
secondViewController!.modalPresentationStyle = .fullScreen
self.navigationController?.present(secondViewController!, animated: false, completion: nil)
})

您正在做的是尝试对向视图添加动画进行动画处理。 动画块需要 1 秒才能完成。基本上,它试图在一秒钟内对动画的添加进行动画处理。完成后,它开始导航。 与其这样做,不如使用 CATransaction 来创建所需的功能。

CATransaction.begin()
CATransaction.setCompletionBlock {
if let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "PageVC") as? PageVC {
secondViewController.modalPresentationStyle = .fullScreen
self.navigationController?.present(secondViewController, animated: false, completion: nil)
}
}
let animation = CATransition()
animation.duration = 1
animation.startProgress = 0.0
animation.endProgress = 1
animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
animation.type = CATransitionType(rawValue: "pageCurl")
animation.subtype = CATransitionSubtype(rawValue: "fromRight")
animation.isRemovedOnCompletion = false
animation.isRemovedOnCompletion = false
self.selectedCell!.view1.layer.add(animation, forKey: "pageFlipAnimation")
CATransaction.commit()

相关内容

最新更新