Die Push/Pop-Animationen des Standardnavigationscontrollers verdunkeln die Ansicht, aus der Sie drücken, und die, auf die Sie gerade zugreifen. Wenn Sie das nicht möchten, können Sie den Übergang anpassen, um eine Animation verwenden, die nur gleitet Ansichten in und aus, aber hat kein Dimmen von etwas:
// this is the view controller you are pushing from
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.delegate = self
}
}
// make the view controller conform to `UINavigationControllerDelegate`
extension ViewController: UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return PushPopAnimator(operation: operation)
}
}
// The animation controller
class PushPopAnimator: NSObject, UIViewControllerAnimatedTransitioning {
let operation: UINavigationControllerOperation
init(operation: UINavigationControllerOperation) {
self.operation = operation
super.init()
}
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.5
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let from = transitionContext.viewController(forKey: .from)!
let to = transitionContext.viewController(forKey: .to)!
let rightTransform = CGAffineTransform(translationX: transitionContext.containerView.bounds.size.width, y: 0)
if operation == .push {
to.view.transform = rightTransform
transitionContext.containerView.addSubview(to.view)
UIView.animate(withDuration: transitionDuration(using: transitionContext), animations: {
to.view.transform = .identity
}, completion: { finished in
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
})
} else if operation == .pop {
to.view.transform = .identity
transitionContext.containerView.insertSubview(to.view, belowSubview: from.view)
UIView.animate(withDuration: transitionDuration(using: transitionContext), animations: {
from.view.transform = rightTransform
}, completion: { finished in
from.view.transform = .identity
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
})
}
}
}
Informationen zu benutzerdefinierten Übergänge mit Blick Controllern finden WWDC 2013 video Custom Transitions Using View Controllers.
Ja. Dies ist der Fall, wenn der verlassende View-Controller animiert wird. Mit Push und Present. Nicht wenn man einen Controller modal von unten präsentiert. – user7684436
Aus einer Perspektive ist es so, als würde das Segment eine Schatten-Überlagerung auf den ausgehenden View-Controller für Ästhetik hinzufügen. Nicht sicher, wie Sie es entfernen können. – user7684436
Ja, der Standard-Push/Pop scheint die Ansicht zu verdunkeln, aus der du schiebst, und die, auf die du schießt. Wenn Ihnen das nicht gefällt, müssen Sie wahrscheinlich Ihre eigene benutzerdefinierte Navigations-Controller-Animation definieren. – Rob