Search code examples
iosiphonepaginationuiscrollviewzooming

How does the UIScrollView delegate know about my UIScrollView ivar?


I'm working on a app that has a paging UIScrollView that contains three scrollViews as subviews which display images that you can pinch and zoom on. The code came from Apple's "PhotoScroller" sample code but I've stripped out the tiling functionality because I'm trying to master the basics first.

I can zoom in on my different images and page through them, which is great. When I leave an image that has been zoomed in to go to the next "page" of the pagingScrollView I want it to be restored to it's original zoom size, right now it stays at the zoom level that I left it at.

I imagine I need to write some code that tells the zoomed UIScrollView to go back to the appropriate zoom scale when I get to the next page. My question is how do I do that?

So far I've been working with UIScrollView's Delegate method "scrollViewDidScroll" and and the "contentOffset" property. Another thought is somehow getting a notification that the pagingScrollView has moved to the next "page."

Any ideas?


Solution

  • If you're interested in knowing when the scroll view has stopped (e.g. the user has let go and the scroll view has snapped into position on a new page) you can use scrollViewDidEndDecelerating:. However, the user may scroll several pages before allowing the scroller to fully stop, so the last page the user stopped on may not be the immediately preceding or immediately following page. You can keep a pointer to the current page and each time the user stops on a page restore the previously current page to the default zoom level before updating the current page pointer.