今天我更新了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 )
}
}
}发布于 2019-11-04 23:54:46
将此行添加到您的代码中。
details?.modalPresentationStyle = .fullScreen //完整代码
let details = self.storyboard?.instantiateViewController(withIdentifier: "CollectionViewController")
details?.transitioningDelegate = self.slideAnimatorLeft
details?.modalPresentationStyle = .fullScreen
self.present(details!, animated: true, completion: nil)发布于 2019-11-04 23:57:22
尝试将modalPresentationStyle更改为custom,如下所示:
let details = self.storyboard?.instantiateViewController(withIdentifier: "ViewSettings")
details?.modalPresentationStyle = .custom
details?.transitioningDelegate = self.slideAnimatorLeft
self.present(details!, animated: true, completion: nil)https://stackoverflow.com/questions/58696677
复制相似问题