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

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

Closed
GRiMe2D opened this issue May 27, 2020 · 4 comments

Comments

@GRiMe2D
Copy link

GRiMe2D commented May 27, 2020

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 :

  • Device: iPad mini 4
  • OS: iOS 13.3
  • OverlayContainer Version: 3.5.0-beta.2
@GRiMe2D
Copy link
Author

GRiMe2D commented May 28, 2020

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

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

GRiMe2D commented Jun 1, 2020

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

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!

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