Пользовательский переход IOS, показывающий белый пустой экран при отклонении контроллера представления - PullRequest
0 голосов
/ 18 мая 2018

Я создаю анимацию Hero, например, в магазине приложений IOS. Нажмите на приложение, чтобы открыть страницу сведений, я смог создать анимацию презентации без каких-либо проблем, но когда я попытался отключить анимацию, в течение некоторого времени отображался белый фоновый экран.перепробовал все решения, перечисленные при переполнении стека, такие как добавление только подпредставления, изменение 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()
        }
...