2

I have a screen where I need to present a UIViewController with custom animation, so I'm using UIPresentationController for a custom presentation.

Everything works fine until the user gets a call, the In-call status bar shifts the UITranstionView by 20 pixels, which I'm supposed to reset to zero after the call gets disconnected.

enter image description here

I want to know if there is any way to handle this using UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate.

Or any other way to fix this.

Update

func animateTransition(using 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)
                    })
            }
        }
    }
4

0 回答 0