2011-03-24 523 views
-1

我創建我uiscrollview,當我運行我的應用程序,觸摸滾動視圖,但滾動視圖不滾動。 幫幫我! 想你! 代碼爲:UIScrollView不滾動...

for (int i=0; i<imageCounts; i++) 
{ 
    GalleryProperty *itemVo = [itemList objectAtIndex:i]; 

    //1 button 
    UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0,20,320,460)]; 

    UIImage *image = [UIImage imageWithContentsOfFile:itemVo.pic]; 
    [imageview setImage:image]; 

    [scrollView addSubview:imageview ]; 

    [imageView release]; 
} 
+0

可能重複(http://stackoverflow.com/questions/2824435/ UIScrollView的 - 不滾動) – Javier 2013-03-26 05:48:38

回答

2

必須設置內容大小:中[UIScrollView中進行滾動]

scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * 3, scrollView.frame.size.height); 
0
When initializing set scrollView frame size equal to your View Size. 
and setContent offset size according to the no of images you're showing in the scrollView. 

In your case 

UIScrollView *yourScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)];//init scroll view 

    for (int i=0; i<imageCounts; i++) 
    { 
     GalleryProperty *itemVo = [itemList objectAtIndex:i]; 

     //1 button 
     UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0,20,320,460)]; 

     UIImage *image = [UIImage imageWithContentsOfFile:itemVo.pic]; 
     [imageview setImage:image]; 

     [scrollView addSubview:imageview ]; 

     yourScrollView.contentSize=CGSizeMake(320*i, 460);//set content size here 

     [imageView release]; 
    }