applidium / OverlayContainer

Non-intrusive iOS UI library to implement overlay based interfaces
https://gaetanzanella.github.io/2018-12-17/replicating-apple-maps-overlay
Other
1.15k stars 94 forks source link

`OverlayContainerSheetPresentationController` doesn't update view frame when device is rotated #67

Closed GRiMe2D closed 4 years ago

GRiMe2D commented 4 years ago

Describe the bug OverlayContainerSheetPresentationController doesn't respect device orientation changes and doesn't update the presented view controller's view

Expected behavior OverlayContainerSheetPresentationController will update its content view within the device rotation animation

Screenshots, videos or sample codes video demo.mp4.zip

Screen Shot 2020-05-27 at 6 10 16 PM

Environnement :

GRiMe2D commented 4 years ago

Seems the problem is more related with OverlayContainerViewController itself.

Because, I've tried to present OverlayContainerViewController without any presentation controller, and it reproduced the same bug (when used with modalPresentationStyle = .overCurrentContext), but it is presented modally (default values) it resizes well

gaetanzanella commented 4 years ago

That's interesting! Thanks.

I tried to reproduce the bug without any overlay container code:

class ViewController: UIViewController {

    private lazy var button = UIButton(type: .system)

    // MARK: - UIViewController

    override func viewDidLoad() {
        super.viewDidLoad()
        setUp()
    }

    // MARK: - Private

    @objc private func buttonAction(_ sender: UIButton) {
        let container = ColoredViewController()
        container.modalPresentationStyle = .overCurrentContext
        present(container, animated: true, completion: nil)
    }

    private func setUp() {
        view.addSubview(button)
        button.setTitle("Show", for: .normal)
        button.translatesAutoresizingMaskIntoConstraints = false
        button.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
        button.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        button.addTarget(self, action: #selector(buttonAction(_:)), for: .touchUpInside)
    }
}

Simulator Screen Shot - iPad (7th generation) - 2020-05-29 at 17 27 23

I found out the default UIViewControllerAnimatedTransitioning does not use constraints but an autoresizing mask. Try to modify the container one:

let container = OverlayContainerViewController()
container.view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
container.modalPresentationStyle = .overCurrentContext
present(container, animated: true, completion: nil)
GRiMe2D commented 4 years ago

Thanks, this fixed the issue. It seems by default UIViewController generates a view with [.flexibleHeight, .flexibleWidth] installed. I believe that's why we usually don't set autoresizing masks to the root view of the view controller.

I think we could do the same thing on OverlayContainerViewController::loadView. What you you think?

gaetanzanella commented 4 years ago

You are right. My ColoredVC uses a custom view.

class ColoredViewController: UIViewController {
    override func loadView() {
        view = UIView()
        view.backgroundColor = .systemBlue
    }
}

If I use a pure empty view controller instead, it works correctly.

let vc = UIViewController()
vc.view.backgroundColor = .systemBlue

I will change the mask in the next release. Thanks!