Rectangle 27 0

ios UIScrollView imagephoto viewer with paging enabled and zooming?


And, here is a link to the iTunes WWDC page:

Big news for those who haven't heard. Apple has released the 2010 WWDC session videos to all members of the iphone developer program. One of the topics discussed is how they created the photos app!!! They build a very similar app step by step and have made all the code available for free.

For those that don't want to hunt through all of the sessions and sample code, you're looking for session 104, Designing Apps with Scroll Views.

I agree. Clearly they found a way around this for the Photos app. It either tiles the images on the fly or has some other way for handling large images.

I just finished watching the session video and looking through the sample code, and it's really good stuff. My one complaint: the ultimate goal of using CATiledLayer for great performance and low memory use requires pre-processing images into tiles. At best, this can be extremely inconvenient.

It does not use private api either. Here is a link to the sample code download. You will probably need to login to gain access.

Note that cutting images into tiles and naming them all right for a give zoom level is just a one-line command with ImageMagick: stackoverflow.com/questions/3245351/iphone-tiling-an-image

Yes, they expect that each image will be one image, perhaps very high resolution, and they use CATiledLayer and generate the tiles inside some drawing code.

Note
Rectangle 27 0

ios UIScrollView imagephoto viewer with paging enabled and zooming?


Figured you'd probably worked that out by now! But these older questions hang on at the top of Google search results, so thought it was worth adding.

If you have a lot of photos, to save memory you can just have two inner UIScrollViews and two UIImagesViews. You then dynamically flip between them, moving their position within the outer UIScrollView and changing their images as the user scrolls the outer UIScrollView. It's a bit more complex but the same principle.

It's essentially what Apple does in its PhotoScroller example (and the 2010 WWDC talk linked to in Jonah's answer). Only in those examples, they've added a whole bunch of complex tiling and other memory management. If you don't need the tiling etc. and if you dont want to wade through those examples and try and remove the bits related to it, the underlying principle of nesting UIScrollViews is actually quite simple:

That's it. Works just like the photo app.

This answer deserves way more up votes as of now: I just solved the whole problem with only a few lines of code using nested scroll views (on iOS 6 in my case).

Yeah nested scrollviews now work correctly. When I originally posted this question, support for iOS 3.2 was important, but nested scroll views had all sorts of issues.

You say you've seen discussions of nesting UIScrollViews but don't want to go there - but that is the way to go! It works easily and well.

Note
Rectangle 27 0

ios UIScrollView imagephoto viewer with paging enabled and zooming?


scrollViewDidScroll:
viewForZoomingInScrollView:
  • A single UIScrollView and a single UIScrollViewDelegate
  • Do some math and figure out what page you are currently on
  • Listen for scrollViewDidEndZooming:withView:atScale: and optionally do some anti-aliasing, etc based on the content
  • Populate the UIScrollView with UIImageView children
  • Return a different view depending on the page index

I did some playing around with the native Photos app, and I think I can say with confidence they are using a single UIScrollView. The giveaway is this: zoom in on an image, and pull to the left or right. You will see the next or previous photo. If you tug hard enough, it will even page to the next photo at 1.0f zoom. Flip back and the previously zoomed photo will be back to 1.0f zoom as well.

If you decide to try that out, let me know how it works out for you. I'd love to know how you finally end up getting this to work. Even better, post it to github.

Note
Rectangle 27 0

ios UIScrollView imagephoto viewer with paging enabled and zooming?


Have you tried a CATiledLayer?

I did some playing around with the native Photos app, and I think I can say with confidence they are using a single UIScrollView. The giveaway is this: zoom in on an image, and pull to the left or right. You will see the next or previous photo. If you tug hard enough, it will even page to the next photo at 1.0f zoom. Flip back and the previously zoomed photo will be back to 1.0f zoom as well.

I even tried creating super low-qual versions of my media, in case that was the problem. With each image weighing in at around 10k (these are jpegs, mind you)... you guessed it. The hang's still there.

I only have one NSOperationQueue running, and I've tried fiddling with the max number of concurrent operations. My thought was that the main thread was getting clogged by competing Queues, or maybe even one queue trying to do to much... still, the hang.

I suspect that apple sets this off as soon as the previous pic has disappeared.

I'm pretty much resolved to do what I've done before and use TTPhotoViewController from Three20. I've spent some hours swimming through that code, and it's always a great education. At this point, though, I would really like to know where the heck this hang comes from, if only so I can spend my can't-sleep hours wondering about something less brain boiling.

Nope... have you?

This is wrong. I'm using nested scrollviews, and getting exactly the same effect. If you're using some memory management scheme (which I had to start using... my page number is fairly high ('bout 50 each in 2 scrollViews)), then you can use a mechanism similar to whatever you have triggering your page loads / unloads to trigger a zoom reset for the pages -1 and +1 from the current page.

What I don't understand is how to achieve smooth scrolling between pages - there's always a very short hang at the moment of transition. Do not get it. I've gotten pretty deep into fixing it - NSInvocationOperations were my first stop, then I made a reusable views queue for the page views (which retain their image views)... still this durned hang.

Note
Rectangle 27 0

ios UIScrollView imagephoto viewer with paging enabled and zooming?


Great work .. Thanks a lot

I've written a simple and easy to use photo browser called MWPhotoBrowser. I decided to create it as Three20 was too heavy/bloated as all I needed was a photo viewer.

MWPhotoBrowser can display one or more images by providing either UIImage objects, or URLs to files, web images or library assets. The photo browser handles the downloading and caching of photos from the web seamlessly. Photos can be zoomed and panned, and optional (customisable) captions can be displayed. The browser can also be used to allow the user to select one or more photos using either the grid or main image view.

Please see the README file.

i got nothing to say but thanks to all you awesome developers who choose to share your great work with everyone. thanks a million!

one more thing I would like to know... It starts from first image only, at where I should change so I can start image viewing from selected image ????

Note
Rectangle 27 0

ios UIScrollView imagephoto viewer with paging enabled and zooming?


Have you tried a CATiledLayer?

I did some playing around with the native Photos app, and I think I can say with confidence they are using a single UIScrollView. The giveaway is this: zoom in on an image, and pull to the left or right. You will see the next or previous photo. If you tug hard enough, it will even page to the next photo at 1.0f zoom. Flip back and the previously zoomed photo will be back to 1.0f zoom as well.

I even tried creating super low-qual versions of my media, in case that was the problem. With each image weighing in at around 10k (these are jpegs, mind you)... you guessed it. The hang's still there.

I only have one NSOperationQueue running, and I've tried fiddling with the max number of concurrent operations. My thought was that the main thread was getting clogged by competing Queues, or maybe even one queue trying to do to much... still, the hang.

I suspect that apple sets this off as soon as the previous pic has disappeared.

I'm pretty much resolved to do what I've done before and use TTPhotoViewController from Three20. I've spent some hours swimming through that code, and it's always a great education. At this point, though, I would really like to know where the heck this hang comes from, if only so I can spend my can't-sleep hours wondering about something less brain boiling.

Nope... have you?

This is wrong. I'm using nested scrollviews, and getting exactly the same effect. If you're using some memory management scheme (which I had to start using... my page number is fairly high ('bout 50 each in 2 scrollViews)), then you can use a mechanism similar to whatever you have triggering your page loads / unloads to trigger a zoom reset for the pages -1 and +1 from the current page.

What I don't understand is how to achieve smooth scrolling between pages - there's always a very short hang at the moment of transition. Do not get it. I've gotten pretty deep into fixing it - NSInvocationOperations were my first stop, then I made a reusable views queue for the page views (which retain their image views)... still this durned hang.

Note
Rectangle 27 0

ios UIScrollView imagephoto viewer with paging enabled and zooming?


Great work .. Thanks a lot

I've written a simple and easy to use photo browser called MWPhotoBrowser. I decided to create it as Three20 was too heavy/bloated as all I needed was a photo viewer.

MWPhotoBrowser can display one or more images by providing either UIImage objects, or URLs to files, web images or library assets. The photo browser handles the downloading and caching of photos from the web seamlessly. Photos can be zoomed and panned, and optional (customisable) captions can be displayed. The browser can also be used to allow the user to select one or more photos using either the grid or main image view.

Please see the README file.

i got nothing to say but thanks to all you awesome developers who choose to share your great work with everyone. thanks a million!

one more thing I would like to know... It starts from first image only, at where I should change so I can start image viewing from selected image ????

Note
Rectangle 27 0

ios UIScrollView imagephoto viewer with paging enabled and zooming?


sure would be nice if apple built an image viewer like the photos app into the SDK for us to use. I'm currently using three20 and it works great. But it is a lot of extra stuff to carry around when all you really want is the photo viewer.

Note
Rectangle 27 0

ios UIScrollView imagephoto viewer with paging enabled and zooming?


And, here is a link to the iTunes WWDC page:

Big news for those who haven't heard. Apple has released the 2010 WWDC session videos to all members of the iphone developer program. One of the topics discussed is how they created the photos app!!! They build a very similar app step by step and have made all the code available for free.

For those that don't want to hunt through all of the sessions and sample code, you're looking for session 104, Designing Apps with Scroll Views.

I agree. Clearly they found a way around this for the Photos app. It either tiles the images on the fly or has some other way for handling large images.

I just finished watching the session video and looking through the sample code, and it's really good stuff. My one complaint: the ultimate goal of using CATiledLayer for great performance and low memory use requires pre-processing images into tiles. At best, this can be extremely inconvenient.

It does not use private api either. Here is a link to the sample code download. You will probably need to login to gain access.

Note that cutting images into tiles and naming them all right for a give zoom level is just a one-line command with ImageMagick: stackoverflow.com/questions/3245351/iphone-tiling-an-image

Yes, they expect that each image will be one image, perhaps very high resolution, and they use CATiledLayer and generate the tiles inside some drawing code.

Note
Rectangle 27 0

ios UIScrollView imagephoto viewer with paging enabled and zooming?


Figured you'd probably worked that out by now! But these older questions hang on at the top of Google search results, so thought it was worth adding.

If you have a lot of photos, to save memory you can just have two inner UIScrollViews and two UIImagesViews. You then dynamically flip between them, moving their position within the outer UIScrollView and changing their images as the user scrolls the outer UIScrollView. It's a bit more complex but the same principle.

It's essentially what Apple does in its PhotoScroller example (and the 2010 WWDC talk linked to in Jonah's answer). Only in those examples, they've added a whole bunch of complex tiling and other memory management. If you don't need the tiling etc. and if you dont want to wade through those examples and try and remove the bits related to it, the underlying principle of nesting UIScrollViews is actually quite simple:

That's it. Works just like the photo app.

This answer deserves way more up votes as of now: I just solved the whole problem with only a few lines of code using nested scroll views (on iOS 6 in my case).

Yeah nested scrollviews now work correctly. When I originally posted this question, support for iOS 3.2 was important, but nested scroll views had all sorts of issues.

You say you've seen discussions of nesting UIScrollViews but don't want to go there - but that is the way to go! It works easily and well.

Note