Note that there are some explanatory texts on larger screens.

plurals
  1. POUIScrollView image/photo viewer with paging enabled and zooming
    primarykey
    data
    text
    <p>OK, I think it's time to make an official place on the internet for this problem: How to make a <code>UIScrollView</code> photoviewer with paging and zooming. Welcome my fellow <code>UIScrollView</code> hackers.</p> <p>I have a <code>UIScrollView</code> with paging enabled, and I'm displaying <code>UIImageViews</code> like the built-in photos app. (Does this sound familiar yet?)</p> <p>I found the following project on github:</p> <p><a href="http://wiki.github.com/andreyvit/ScrollingMadness" rel="noreferrer">http://wiki.github.com/andreyvit/ScrollingMadness</a></p> <p>Which shows how to implement zooming in a scroll view while paging is enabled. If anyone else tries this out, I actually had to remove the <code>UIScrollView</code> subclass and use the native class otherwise it doesn't work. I think it's because of changes in the 3.0 SDK relating to how the scroll view intercepts touch events.</p> <p>So the the idea is to remove all the other views when you start zooming, and move the current view to (0, 0) in the <code>scrollview</code>, updating the <code>contentsize</code> etc. Then when you zoom back to 1.0f it adds the other views back and puts things all back in order.</p> <p>Anyway, that project works perfectly in the simulator, but on the device there is some nasty movement of the view you are resizing, which looks like it's caused by the fact we are changing the <code>contentsize</code>/<code>offset</code> etc. for the view being resized. You have to do this view moving otherwise you can pan left through the whitespace left by the other views.</p> <p>I found one interesting note in the "Known Issues" of the <a href="http://developer.apple.com/iphone/prerelease/library/releasenotes/General/RN-iPhoneSDK-3/index.html" rel="noreferrer">3.0 SDK release notes</a>:</p> <blockquote> UIScrollView: After zooming, content inset is ignored and content is left in the wrong position. </blockquote> <p>This kind of sounds like what is happening here. After zooming in, the view will shift offscreen because you have changed the offset etc.</p> <p>I've spent hours on this already and I'm slowing coming to the sad realization that this just isn't going to work.</p> <p>Three20's photo viewer is out of the question: it's too heavy weight and there is too much unnecessary UI and other behaviour.</p> <p>The built in Photo app seems to do some magic. If you zoom in on an image and pan to the far edges, the current photo moves independently of the photo next to it which isn't what you get when trying this with a standard <code>UIScrollView</code>.</p> <p>I've seen discussion about nesting the <code>UIScrollView</code>'s but I really don't want to go there.</p> <p>Has anybody managed this with the standard <code>UIScrollView</code> (and works in the 2.2 and 3.0 SDK)? I don't fancy rolling my own zoom + bounce + pan + paging code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload