views:

48

answers:

2

I am currently researching ways of adding several UIImageView's to a single UIScrollView. The UIScroll view will be 1.5 times the size of any one of the UIImageView's. I want to create a scrolling effect for browsing through some small images in an iPad application. Does anyone know how to achieve this?

+1  A: 

If you want zoom and everything:

http://developer.apple.com/library/ios/#samplecode/PhotoScroller/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40010080

If you just want a paging scrollview:

http://developer.apple.com/library/ios/#samplecode/PageControl/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40007795

Larsaronen
Thanks mate, will give it a try but looks quite involved!
TheLearner
+1  A: 
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(/*FRAME*/)]; // this makes the scroll view - set the frame as the size you want to SHOW on the screen
[scrollView setContentSize:CGSizeMake(/*SIZE OF THE CONTENT*/)]; // if you set it to larger than the frame the overflow will be hidden and the view will scroll

/* you can do this bit as many times as you want... make sure you set each image at a different origin */
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"/*IMAGE*/"]]; // this makes the image view
[imageView setFrame:CGRectMake(/*SET AS 2/3 THE SIZE OF scrollView AND EACH IMAGE NEXT TO THE LAST*/)]; // this makes the image view display where you want it and at the right size
[scrollView addSubview:imageView]; // this adds the image to the scrollview
/* end adding image */

[self.view addSubview:scrollView];
Thomas Clayson
OK got you mate! Will give it a try!
TheLearner
Great explanation thanks mate. Is there anyway to force the scroll bars to be visible at all times?
TheLearner
Or a way to make it animate or something so that user knows they can scroll
TheLearner
Good explenation! Also remember to release the allocated views after adding them as subviews. I recomend checking out the second link i gave you if you want to learn how to implement paging (Snaps to imageview) and a page indicator, how to release images outside of view. And the first link if you want to be able to zoom on images.
Larsaronen
yes sorry - having come from a php background my main issue is with memory management. The best way (i've found) to do it is to put [[...] autorelease] around your elements - that way you don't have to remember to release them (until you get EXC_BAD_ACCESS and all sorts... :p)
Thomas Clayson
Yeah I also have issues with Mem Management but the apple guide is REALLY worth the read!
TheLearner