Skip to content

UIPresentationController issues #2

Open
@mariohahn

Description

@mariohahn

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions