Kodeco Forums

Video Tutorial: Swift Scroll View School Part 6: Nested Scroll Views

In this video tutorial you'll learn how to nest scroll views inside another scroll view.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3911-scroll-view-school/lessons/7

I can’t get the image to display properly scaled to fit and centered after rotating to landscape. I have this code:
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
setZoomParamForSize(scrollView.bounds.size)
centerImage()
}
I have everything setup with auto layout. Scrollview to view 0 0 0 0 and image view to scrollview 0 0 0 0. Also tried willTransition, but no success. Any idea how to fix this?

Edit: I managed to fix it! Apparently the code was called while the view was not correctly calculated yet after rotation. So I put the code in a DispatchQueue.main.async.
DispatchQueue.main.async {
self.setZoomParamForSize(self.scrollView.bounds.size)
self.centerImage()
}