3
  1. I have a UIScrollView of size 320*460 and with content size 1024*1024.
  2. I can place 25 images of 256*256 in it with the 13th picture shown at the centre of the screen when it loades with bits of surrounding pictures around it.
  3. When i swipe to any side I want it to appear just like the mapView. With new images appearing and showing.

How can I do it?

wolverine
  • 2,967
  • 5
  • 31
  • 35
  • 2
    This is possibly a duplicate of http://stackoverflow.com/questions/1710781/uiscrollview-infinite-scroll and http://stackoverflow.com/questions/1493950/uiscrollview-any-thoughts-on-implementing-infinite-scroll-zoom . The latter question has a workable solution. – Brad Larson Dec 06 '09 at 15:35

3 Answers3

1

It's very easy & somewhat tricky...

You don't need to define the specific size for the ScrollView.....

Generally we use to define ....as per the Examples of Apple

//#define SCROLLVIEW_CONTENT_HEIGHT 460

//#define SCROLLVIEW_CONTENT_WIDTH  320

which is of no use...if you need the infinite height..

just set the height of the ScrollView dynamically as per the Objects added to the ScrollView....

No need to set the predefined height for this...take the dynamic height....

scrollview.contentSize = CGSizeMake(320, txtView.contentSize.height+450);
 CGPoint topOffset = CGPointMake(0,0);
 [scrollview setContentOffset:topOffset animated:YES];

Hope this will surely work for you..

Good Luck :)

DShah
  • 9,768
  • 11
  • 71
  • 127
Ajay Sharma
  • 4,509
  • 3
  • 32
  • 59
0

Checkout the sample code called 'Tiling'. It might be what you're looking for.

Jessedc
  • 12,320
  • 3
  • 50
  • 63
0

When scrolling stops, couldn't you just adjust the bounds so that you are now "re-centered" with your new offset?

Presumably you can't scroll more than so many pixels before your finger hits the edge of the screen, so you only need bounds that a few hundred pixels outside the original center.

Once you have a new center, adjust your bounds accordingly, retiling as necessary.

Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
  • Ok, one doubt.In what i am doing, after placing each image, I am releasing its memory. When the scrollView loads, it shows all these images. But as u said when i does tiling, if i try to cache some of those images, wont it cause problems for me? – wolverine Dec 04 '09 at 10:13
  • I'm not sure what you mean, but you should probably release an image once it is outside the new bounds, adding new image tile references as needed. – Alex Reynolds Dec 04 '09 at 10:18
  • 1
    I'm still going to insist you look at how Tiling sample code and learn the ins and outs of it. As Alex points out the 'infinite scrolling' you're looking for is more of a visual effect than a function of UIScrollView. – Jessedc Dec 05 '09 at 02:17
  • As I mention in a comment for http://stackoverflow.com/questions/1493950/uiscrollview-any-thoughts-on-implementing-infinite-scroll-zoom `setContentOffset` cancels whatever scrolling is taking place, so on the face of it, this approach won't work. – Grumdrig Apr 05 '10 at 21:36
  • It seems `setContentOffset:animated:` cancels current scrolling, but not `setContentOffset:`... Overriding `setContentOffset:` in a descendant of `UIScrollView` and tweaking offset works ! (at least on iOS SDK 4.3) – Damien Debin Jun 30 '11 at 08:31