cocoatoucher / AICustomViewControllerTransition

Easy and tidy way for creating custom UIViewController transitions for iOS
MIT License
139 stars 17 forks source link

UIPresentationController issues #2

Open mariohahn opened 7 years ago

mariohahn commented 7 years ago

Hi,

have you ever tried to use your lib together with a UIPresentationController?

example:

class TVPlayerPresentationController: UIPresentationController {

    let dimmingView: UIView = {
        $0.translatesAutoresizingMaskIntoConstraints = false
        $0.alpha = 0
        $0.backgroundColor = UIColor.black

        return $0
    }(UIView())

    override func presentationTransitionWillBegin() {
        super.presentationTransitionWillBegin()

        guard let container = containerView else { return }

        container.addSubview(dimmingView)

        NSLayoutConstraint.activate([
            dimmingView.leadingAnchor.constraint(equalTo: container.leadingAnchor),
            dimmingView.trailingAnchor.constraint(equalTo: container.trailingAnchor),
            dimmingView.topAnchor.constraint(equalTo: container.topAnchor),
            dimmingView.bottomAnchor.constraint(equalTo: container.bottomAnchor)
        ])

        guard let coordinator = presentedViewController.transitionCoordinator else {
            dimmingView.alpha = 1.0
            return
        }

        coordinator.animate(alongsideTransition: { _ in
            self.dimmingView.alpha = 1.0
        })
    }

    func updateInteractivePresentation(with percentage: CGFloat) {
        dimmingView.alpha = percentage
    }

    override func presentationTransitionDidEnd(_ completed: Bool) {
        super.presentationTransitionDidEnd(completed)

        dimmingView.removeFromSuperview()
    }

    override func dismissalTransitionWillBegin() {
        guard let coordinator = presentedViewController.transitionCoordinator else {
            dimmingView.alpha = 0.0
            return
        }

        coordinator.animate(alongsideTransition: { _ in
            self.dimmingView.alpha = 0.0
        })
    }
}

class TVPlayerTransitioningDelegate: InteractiveTransitioningDelegate {

    func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
        return TVPlayerPresentationController(presentedViewController: presented, presenting: presenting)
    }
}

It works fine for none interactive transitions:

1.) DimmingView 2.) ToViewController.view

But the real problem is the interactive transition:

1.) DimmingView 2.) FromViewController.view 3.) ToViewController.view

So my dimming view is not visible because you add the FromViewController.view to the ContainerView.

Is there any reason why you would add the FromViewController.view in general to the ContainerView?

cocoatoucher commented 7 years ago

Thanks for the input. I'll have a detailed look and consider not moving fromViewController.view to containerView I think the basic reason was to be able to animate the whole container view but I'll confirm that

mariohahn commented 7 years ago

Have you already tried to use a PresentationController? đŸ™ƒ

cocoatoucher commented 7 years ago

No I didn't try to use it with the framework actually yet, if that's the question The initial implementation is coming from iOS 7 times and that framework was sufficient for most of the scenarios but I'll have a look at it

However, feel free to open a pull request with any improvements you had in mind