Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIPresentationController issues #2

Open
mariohahn opened this issue Apr 21, 2017 · 3 comments
Open

UIPresentationController issues #2

mariohahn opened this issue Apr 21, 2017 · 3 comments

Comments

@mariohahn
Copy link

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
Copy link
Owner

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
Copy link
Author

Have you already tried to use a PresentationController? 🙃

@cocoatoucher
Copy link
Owner

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

Repository owner deleted a comment from DavideStagni Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants