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:
If you just want a paging scrollview:
Larsaronen
2010-09-23 10:31:01
Thanks mate, will give it a try but looks quite involved!
TheLearner
2010-09-23 10:43:12
+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
2010-09-23 10:39:07
Great explanation thanks mate. Is there anyway to force the scroll bars to be visible at all times?
TheLearner
2010-09-23 11:00:37
Or a way to make it animate or something so that user knows they can scroll
TheLearner
2010-09-23 11:08:38
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
2010-09-23 11:22:51
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
2010-09-23 11:33:31
Yeah I also have issues with Mem Management but the apple guide is REALLY worth the read!
TheLearner
2010-09-23 12:19:22