自定义IOS转换显示白色空白屏幕同时解除视图控制器

时间:2018-05-18 04:44:35

标签: ios objective-c swift animation ios-animations

我正在创建像IOS应用程序商店的Hero动画点击应用程序打开详细信息页面,我能够创建演示动画而没有任何问题但是当我试图解除动画时它显示白色背景屏幕一段时间,我尝试了所有在堆栈溢出上列出的解决方案,如添加子视图只有时间,将modalPresentationStyle更改为.fullscreen但在解雇期间无法摆脱白色背景下面是我的示例代码

let today = TodayDetailViewController()
        today.transitioningDelegate = self
        today.modalPresentationStyle = .fullScreen
        guard let cell = collectionView.cellForItem(at: indexPath) else {
            return;
        }
        let cellFrame = collectionView.convert(cell.frame, to: collectionView.superview)
        modelTransition.originFrame = cellFrame;
        present(today, animated: true, completion: nil);

- 动画转换方法

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        let containerView = transitionContext.containerView
        guard let fromView = transitionContext.view(forKey: UITransitionContextViewKey.from) else { return }
        guard let toView = transitionContext.view(forKey: UITransitionContextViewKey.to) else { return }
        let modalView: UIView = presenting ? toView : fromView

        if(!presenting){

            edgeLayoutConstraints?.constants(to: 0)
            let animator = UIViewPropertyAnimator(duration: duration, dampingRatio: 0.8)
            animator.addAnimations {
                self.edgeLayoutConstraints?.match(to: self.originFrame,
                                             container: containerView)
                containerView.layoutIfNeeded()
                modalView.layoutIfNeeded()

            }
            animator.addCompletion { position in
                switch position {
                case .end:

                    transitionContext.completeTransition(true)
                default:
                    transitionContext.completeTransition(true)
                }
            }
            animator.startAnimation()


        }
        else{

            modalView.translatesAutoresizingMaskIntoConstraints = false
            containerView.addSubview(toView)

            edgeLayoutConstraints = NSEdgeLayoutConstraints(view: modalView,
                                                            container: containerView,
                                                            frame: originFrame)
            edgeLayoutConstraints?.toggleConstraints(true)
            containerView.layoutIfNeeded()
            modalView.layoutIfNeeded()
            let animator = UIViewPropertyAnimator(duration: duration, dampingRatio: 0.8)
            animator.addAnimations {
                self.edgeLayoutConstraints?.constants(to: 0)
                containerView.layoutIfNeeded()
                modalView.layoutIfNeeded()

            }
            animator.addCompletion { position in
                switch position {
                case .end:
                    transitionContext.completeTransition(true)
                default:
                    transitionContext.completeTransition(true)
                }
            }
            animator.startAnimation()
        }

0 个答案:

没有答案