Closed GRiMe2D closed 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
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!
Describe the bug
OverlayContainerSheetPresentationController
doesn't respect device orientation changes and doesn't update the presented view controller's viewExpected behavior
OverlayContainerSheetPresentationController
will update its content view within the device rotation animationScreenshots, videos or sample codes video demo.mp4.zip
Environnement :