What if the pages are different heights? Could you give some direction on how to handle this situation? And, by different heights, I mean they scroll vertically, off the page, in addition to paging horizontally.
Are there Swift 3 files for these lessons? I downloaded Lesson 12 & tried to do the automatic conversion, but some items aren’t converting.
Thanks!
J
Hi @gallaugher, thanks for getting a Swift 3 version up and running!
The min/max calls are to clamp the value and make sure the page argument is within the bounds. So max(0, page) ensures the value will not be a negative number (less than 0) and min(x, pageCount-1) ensures the value will not be greater than the index of the final page.
If you pass in a negative number mistakenly for inPage it will be set to 0; if you pass in a really large number beyond the actual number of pages, the value will get set to pageCount-1.
In short, it’s a safety feature to ensure we don’t go out of bounds.
I hope that helps, and thanks for the question and the code!
–Greg
Super - thanks. I tried removing this & noticed that there were situations where my code crashed, perhaps because events are firing in ways that are unexpected, so having the extra check is useful. Thanks again for the tutorial!
J
First of all, thank you for putting up these scrollview lessons, they’ve been extremely informative and helpful. I am trying implement a scrollview with peeking views (like what the safari app used to have for switching between tabs). I’m trying to implement with autolayout but cannot get the view to center properly when there are left and right views to either side. I pinned the scrollview edges so that the scrollview is narrower than the superview, and tried modifying the padding, but am not able to get the current view centered properly.