UIPresentationController В строке состояния звонка проблема
У меня есть экран, где мне нужно представить UIViewController
с пользовательской анимацией, поэтому я использую UIPresentationController
для индивидуальной презентации.
Все работает нормально, пока пользователь не получит звонок, строка состояния In-call сдвигает UITranstionView
на 20 пикселей, который я должен сбросить до нуля после того, как вызов будет отключен.
Я хочу знать, есть ли способ справиться с этим, используя UIViewControllerAnimatedTransitioning
, UIViewControllerTransitioningDelegate
,
Или любой другой способ исправить это.
Обновить
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)
})
}
}
}