迅捷的segue过渡阴影

use*_*436 1 storyboard ios segue swift

我正在使用故事板中的一些标准标记,每个标记都有相同的背景色。我遇到的问题是,当segue过渡快要完成时,整个框架周围都会出现像背景这样的深色阴影。

该图显示了过渡

这很微弱,但足以引起问题。有人遇到过吗?

Rob*_*Rob 5

标准导航控制器的“推/弹出”动画会使您要从其推入的视图和要弹出的视图变暗。如果您不喜欢这种方式,则可以使用一种动画来自定义过渡,该动画只能将视图滑动进出,而不会使任何内容变暗:

// 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)
            })
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

有关使用视图控制器进行自定义过渡的信息,请参阅WWDC 2013视频使用视图控制器进行自定义过渡