2013-10-18 102 views
0

嗨我期待看看我是否可以採用我在下面創建的滾動視圖,並在第3或第4張圖片上啓動滾動視圖,而不是從頭開始滾動視圖。基本上我不想讓它從第一張圖片開始,但仍然能夠向後滾動以獲得它們。這可能嗎?謝謝!開始ScrollView除了第一張圖片

int PageCount = 34; 
     NSMutableArray *arrImageName =[[NSMutableArray alloc]initWithObjects:@"4miley.png",@"4BP1-2.png",@"S2-4.png",@"D3-4.png",@"4BP1-1.png",@"F2-4.png",@"B6-4.png",@"D6-4.png",@"4BP1-3.png",@"S1-4.png",@"B7-4.png", @"D2-4.png",@"F7-4.png",@"B1-4.png",@"F3-4.png",@"4BP1-4.png",@"D5-4.png",@"S3-4.png",@"B2-4.png",@"F5-4.png",@"D4-4.png",@"S7-4.png",@"F1-4.png",@"B3-4.png",@"S4-4.png",@"F6-4.png",@"D1-4.png",@"4BP1-5.png",@"B4-4.png",@"S5-4.png",@"F4-4.png",@"D7-4.png",@"S6-4.png",@"B5-4.png",nil]; 

     scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
     scroller.scrollEnabled=YES; 
     scroller.backgroundColor = [UIColor clearColor]; 
     [scroller setShowsHorizontalScrollIndicator:NO]; 
     scroller.pagingEnabled = YES; 
     scroller.bounces = NO; 
     scroller.delegate = self; 
     [self.view addSubview:scroller]; 
     width=scroller.frame.size.width; 
     xPos=0; 
     for (int i=0; i<PageCount; i++) 
     { 
      ImgView = [[UIImageView alloc]initWithFrame:CGRectMake(xPos, 0, scroller.frame.size.width, scroller.frame.size.height)]; 
      [ImgView setImage:[UIImage imageNamed:[arrImageName objectAtIndex:i]]]; 
      [scroller addSubview:ImgView]; 
      scroller.contentSize = CGSizeMake(width, 0); 
      width +=scroller.frame.size.width; 
      xPos +=scroller.frame.size.width; 
     } 

回答

2

在滾動視圖初始化圖像之後,可以使用scrollRectToVisible方法來顯示第三和第四圖像,在該方法中設置第三圖像的幀。

[scroller scrollRectToVisible:frame animated:YES]; 
//frame = your 3rd image 
1

一旦你計算出你的第三或第四圖像的X位置& Y位置,你可以使用

[scrollView setContentOffset:CGPointMake(x, y) animated:YES]; 

[scrollView scrollRectToVisible:rect animated:YES];//put the rect of your image 
0

,滾動型初始化圖像之後,就可以使用setContentOffset:animated:顯示第3或第4張圖像的方法

[scroller setContentOffset:CGPointMake(3*320, 0) animated:YES]; 
相關問題