Well, I think it's time to make an official place on the Internet for this problem: How to make UIScrollView photo viewer with paging and scaling. Welcome my colleagues UIScrollView hackers.
I have swap enabled UIScrollView and I display UIImageViews as a built-in photo app. (Does this sound familiar?)
On github, I found the following project:
https://github.com/andreyvit/ScrollingMadness/wiki
Which shows how to implement scaling in scroll mode when swap is enabled. If someone else tries this, I actually had to remove the UIScrollView subclass and use my own class, otherwise it doesn't work. I think this is due to changes in the 3.0 SDK related to the way the scroll view captures touch events.
So the idea is to remove all other views when you start scaling, and move the current view to (0, 0) in scrollview by updating contentsize , etc. Then, when you get back to 1.0f, other views will be added and come back in order.
In any case, this project works fine in the simulator, but there are some unpleasant movements on the device of the kind whose size you are resizing, and it seems that this is due to the fact that we are changing contentsize / offset , etc. For a view. to be resized You must make this view moving, otherwise you can move left through the space left by other views.
I found one interesting note in the Known Issues section of the 3.0 SDK Release Notes:
UIScrollView: after scaling, the content insertion is ignored, and the content remains in the wrong position.
This view sounds like what's happening here. After zooming in, the image will move off the screen because you changed the offset, etc.
I’ve been doing this for hours, and I slowly come to the sad realization that it just won’t work.
Three20 photo viewer excluded: too much weight, too much unnecessary interface and other behavior.
The built-in Photo app seems to be doing something magical. If you enlarge the image and move to the far edges, the current photo moves regardless of the photo next to it, and this is not what you get when you try to do this with the standard UIScrollView .
I saw a discussion about embedding UIScrollView , but I really don't want to go there.
Has anyone dealt with this with the UIScrollView standard (and works in 2.2 and 3.0 SDKs)? I don’t like it when I use my own zoom + bounce + pan + pager code.