Das UINavigationControllerDelegate Protokoll verfügt über eine Methode, die eine benutzerdefinierte zurückkehren UIViewControllerAnimatedTransitioning-Objekt, das die Animation zwischen den beiden am Übergang beteiligten View-Controllern steuert.
ein Animator-Klasse Erstellen Sie die Quer lösen Übergang zu steuern:
class Animator: NSObject, UIViewControllerAnimatedTransitioning {
let animationDuration = 0.25
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return animationDuration
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)
toVC?.view.alpha = 0.0
let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)
transitionContext.containerView.addSubview(fromVC!.view)
transitionContext.containerView.addSubview(toVC!.view)
UIView.animate(withDuration: animationDuration, animations: {
toVC?.view.alpha = 1.0
}) { (completed) in
fromVC?.view.removeFromSuperview()
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
}
}
}
Und es in Ihrem UINavigationControllerDelegate bieten:
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return Animator()
}
Hier ist eine tiefer gehende Tutorial: http://blog.rinatkhanov.me/ios/transitions.html
Dies macht nicht genau dasselbe. Es löst sich auf, aber es scheint immer noch, als ob es hineingleitet. – BennyTheNerd
Die gleitende (drückende) Animation wird deaktiviert, wenn Sie animiert auf NEIN setzen, also funktioniert es wie erwartet – David