AICustomViewControllerTransition icon indicating copy to clipboard operation
AICustomViewControllerTransition copied to clipboard

UIPresentationController issues

Open mariohahn opened this issue 7 years ago • 3 comments

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?

mariohahn avatar Apr 21 '17 13:04 mariohahn

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

cocoatoucher avatar Apr 25 '17 13:04 cocoatoucher

Have you already tried to use a PresentationController? 🙃

mariohahn avatar Apr 27 '17 08:04 mariohahn

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

cocoatoucher avatar Apr 28 '17 08:04 cocoatoucher