`OverlayContainerSheetPresentationController` doesn't update view frame when device is rotated
Closed this issue · 4 comments
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
Environnement :
- Device: iPad mini 4
- OS: iOS 13.3
- OverlayContainer Version: 3.5.0-beta.2
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
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)
}
}
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)
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?
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!