UIPresentationController通话中状态栏问题

时间:2017-11-15 09:40:14

标签: ios swift uipresentationcontroller

我有一个屏幕,我需要在其中显示带有自定义动画的UIViewController,因此我使用UIPresentationController进行自定义演示。

一切正常,直到用户接听电话,通话中状态栏将UITranstionView移动20个像素,我应该在通话断开后重置为零。

enter image description here

我想知道是否有办法使用UIViewControllerAnimatedTransitioningUIViewControllerTransitioningDelegate处理此问题。

或任何其他解决方法。

更新

func animateTransition(使用transitionContext:

UIViewControllerContextTransitioning){
handlePresentationDismissTransition(transitionContext)
}

fileprivate func handlePresentationDismissTransition(_ transitionContext: UIViewControllerContextTransitioning)
    {
        let container = transitionContext.containerView
        if let fromView = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)?.view , let toView = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)?.view
        {
            var toViewFinalFrame  = toView.frame
            var fromViewFinalFrame = fromView.frame
            var toViewFrame = toView.frame
            let fromViewFrame = fromView.frame

            if actionType == .cardsPresentation
            {
                toView.backgroundColor = UIColor.clear
                toViewFrame = CGRect(x: 0, y: GeneralConstants.screenHeight, width: GeneralConstants.screenWidth, height: GeneralConstants.screenHeight)                
                toViewFinalFrame = CGRect(x: 0, y: 0, width: GeneralConstants.screenWidth, height: GeneralConstants.screenHeight)
                container.backgroundColor = UIColor.black.withAlphaComponent(0.0)
                cardsViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to) as? BaseNC
            }
            else if actionType == .cardsDismissal
            {
                fromViewFinalFrame = CGRect(x: 0, y: GeneralConstants.screenHeight, width: GeneralConstants.screenWidth, height: fromViewFrame.size.height)
            }

            if transitionType == .present
            {
                container.addSubview(toView)
                if actionType == .cardsPresentation
                {
                    toView.frame = toViewFrame
                }

            }

            let duration = self.transitionDuration(using: transitionContext)


            if self.actionType == .cardsPresentation || self.transitionType == .present
            {
                UIView.animate(withDuration: duration, delay: 0.0, options: UIViewAnimationOptions(), animations: {[weak self] () in
                    container.backgroundColor = UIColor.black.withAlphaComponent(self?.actionType == .cardsPresentation ? 0.5: 0.0)
                    toView.frame = toViewFinalFrame

                    }, completion: { [weak self](completed) in
                        if self?.transitionType == .present
                        {
                            self?.transitionType = .dismiss
                        }
                        if self?.actionType == .cardsPresentation
                        {
                            self?.actionType = .cardsDismissal
                        }

                        transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
                })
            }
            else if self.actionType == .cardsDismissal || self.actionType == .cardsInteractiveDismissal
            {
                //This block is used for animating the transform
                UIView.animate(withDuration: duration, delay: 0.0, options: .curveLinear, animations:
                    { [weak self] () in
                        container.backgroundColor = UIColor.black.withAlphaComponent(self?.actionType == .cardsPresentation ? 0.5: 0.0)
                        fromView.frame = fromViewFinalFrame
                    }, completion: {[weak self] finished in

                        if fromView.frame.origin.y >= fromViewFinalFrame.origin.y
                        {
                            self?.transitionHandlerDelegate?.controllerDismissed()
                        }
                        transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
                    })
            }
        }
    }

0 个答案:

没有答案