今天,我更新了Xcode,然后过去几年中所有应用程序中的所有转换都停止了工作。我测试了如何在新的模拟器上以及通过安装到iOS13.2设备上运行它们。但是,当我从App Store下载任何应用程序时,过渡效果很好。我将在稍后的试飞中尝试新的版本。也许这些年来我一直在做错事?
转换代码
let details = self.storyboard?.instantiateViewController(withIdentifier: "ViewSettings")
details?.transitioningDelegate = self.slideAnimatorLeft
self.present(details!, animated: true, completion: nil)
过渡班
class SlideAnimatorLeft: NSObject, UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate {
let duration = 0.9
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return self
}
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return self
}
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return duration
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let fromView = transitionContext.view(forKey: UITransitionContextViewKey.from) else {
return
}
guard let toView = transitionContext.view(forKey: UITransitionContextViewKey.to) else {
return
}
let container = transitionContext.containerView
let screenOffUp = CGAffineTransform(translationX: container.frame.width, y: 0)
let screenOffDown = CGAffineTransform(translationX: -container.frame.width, y: 0)
container.addSubview(fromView)
container.addSubview(toView)
toView.transform = screenOffUp
UIView.animate(withDuration: duration, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.8, options: [], animations: {
fromView.transform = screenOffDown
fromView.alpha = 1
toView.transform = CGAffineTransform.identity
toView.alpha = 1
}) { (success) in
transitionContext.completeTransition(success )
}
}
}
答案 0 :(得分:2)
将此行添加到您的代码中。
details?.modalPresentationStyle = .fullScreen
//完整代码
let details = self.storyboard?.instantiateViewController(withIdentifier: "CollectionViewController")
details?.transitioningDelegate = self.slideAnimatorLeft
details?.modalPresentationStyle = .fullScreen
self.present(details!, animated: true, completion: nil)
答案 1 :(得分:0)
尝试像这样将modalPresentationStyle
更改为custom
:
let details = self.storyboard?.instantiateViewController(withIdentifier: "ViewSettings")
details?.modalPresentationStyle = .custom
details?.transitioningDelegate = self.slideAnimatorLeft
self.present(details!, animated: true, completion: nil)