2010-09-23 86 views
4

我目前正在研究將幾個UIImageView添加到單個UIScrollView的方法。 UIScrollView將是UIImageViews中任意一個的1.5倍。我想創建一個滾動效果來瀏覽iPad應用程序中的一些小圖像。有誰知道如何做到這一點?將UIImageView添加到UIScrollView

回答

11
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]; 
+0

好吧,你有隊友!會試試看! – TheLearner 2010-09-23 10:42:48

+0

很好的解釋感謝隊友。無論如何強迫滾動條始終可見嗎? – TheLearner 2010-09-23 11:00:37

+0

或使其成爲動畫或其他方式,以便用戶知道他們可以滾動 – TheLearner 2010-09-23 11:08:38