ios 7 view with transparent content overlaps previous view

前端 未结 9 1674
独厮守ぢ
独厮守ぢ 2020-12-23 20:25

Recently I updated my xcode project to work with iOS 7, but i faced a big problem. Because my whole application has only one background image (UIImageView added to key windo

9条回答
  •  一向
    一向 (楼主)
    2020-12-23 21:18

    Props to @snoersnoer.


    Here is the code in Swift 3.

    func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    
        let pushTransition = SUPushTransition()
        pushTransition.navigationControllerOperation = operation
        return pushTransition
    }
    

    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
    
        // the containerView is the superview during the animation process.
        let container = transitionContext.containerView
    
        let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)
        let toVC = transitionContext.viewController(forKey:UITransitionContextViewControllerKey.to);
    
        if let from = fromVC,
            let fromView = from.view,
            let to = toVC,
            let toView = to.view {
    
            let containerWidth = container.frame.size.width
    
            // Set the needed frames to animate.
    
            var toInitialFrame = container.frame
            var fromDestinationFrame = fromView.frame
    
            if self.navigationControllerOperation == .push {
                toInitialFrame.origin.x = containerWidth;
                toView.frame = toInitialFrame;
                fromDestinationFrame.origin.x = -containerWidth;
            }
            else if self.navigationControllerOperation == .pop {
                toInitialFrame.origin.x = -containerWidth;
                toView.frame = toInitialFrame;
                fromDestinationFrame.origin.x = containerWidth;
            }
    
            // Create a screenshot of the toView.
            if let move = toView.snapshotView(afterScreenUpdates: true) {
    
                move.frame = toView.frame
                container.addSubview(move)
    
                UIView.animate(withDuration: Constants.MainPage.navControllerDuration, delay: 0.0, usingSpringWithDamping: 1000, initialSpringVelocity: 1, options: .curveEaseInOut, animations: {
                    move.frame = container.frame;
                    fromView.frame = fromDestinationFrame;
                }, completion: { (finished) in
    
                    if finished {
    
                        if !container.subviews.contains(toView) {
                            container.addSubview(toView)
                        }
    
                        toView.frame = container.frame
    
                        fromView.removeFromSuperview()
                        move.removeFromSuperview()
    
                        transitionContext.completeTransition(true)
                    }
    
                })
    
            }
    
        }
    
    }
    

    Cheers.

提交回复
热议问题