I have a popover (alert) as a custom view (UIViewController). As subviews, in storyboard, I have a stack view with some labels and I added a scroll view as superview for stack view. In portrait mode it shows fine, but when moving to landscape I don't know what I have to do to make the stack view scrollable. I tried a lot of approaches: to make the stack view smaller, or to make the scroll view smaller or to embed another content view so the scrolls appears, but it doesn't work. How to make a stack view scrollable when going from portrait to landscape?
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate(alongsideTransition: nil) { _ in
if self.device.isPhone {
let isOrientationLandscape = self.device.orientation == .horizontal
if isOrientationLandscape {
self.scrollView.translatesAutoresizingMaskIntoConstraints = false
self.contentView.translatesAutoresizingMaskIntoConstraints = false
self.contentView.heightAnchor.constraint(equalToConstant: 125.0).isActive = true
self.scrollView.contentSize = CGSize(width: self.scrollView.frame.size.width, height: self.contentView.frame.size.height)
}
}
}