2012-02-16 53 views
1

我需要在我的項目中連續滾動圖像,即從圖像的底部一旦通過繼續滾動到頂部滾動應該從底部開始等等,在一種循環,我該如何做到這一點?連續滾動圖像

感謝

+0

我想你問爲此, http://stackoverflow.com/questions/3763978/360-panorama-librarys-for-ios。 – Vignesh 2012-02-16 07:06:23

回答

1

在這個例子中,我以總共5幅影像

- (void)viewDidLoad { 
     [super viewDidLoad]; 

     // add the last image (image4) into the first position 
     [self addImageWithName:@"image4.jpg" atPosition:0]; 

     // add all of the images to the scroll view 
     for (int i = 1; i < 5; i++) { 
      [self addImageWithName:[NSString stringWithFormat:@"image%i.jpg",i] atPosition:i]; 
     } 

     // add the first image (image1) into the last position 
     [self addImageWithName:@"image1.jpg" atPosition:5]; 

     scrollView.contentSize = CGSizeMake(320, 2496);  
     [scrollView scrollRectToVisible:CGRectMake(0,416,320,416) animated:NO]; 
    } 

    - (void)addImageWithName:(NSString*)imageString atPosition:(int)position { 
     // add image to scroll view 
     UIImage *image = [UIImage imageNamed:imageString]; 
     UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 
     imageView.frame = CGRectMake(0,position*416,320, 416); 
     [scrollView addSubview:imageView]; 
     [imageView release]; 
    } 

實現委託方法

- (void)scrollViewDidEndDecelerating:(UIScrollView *)sender {  
    NSLog(@"%f",scrollView.contentOffset.y); 
    // The key is repositioning without animation  
    if (scrollView.contentOffset.y == 0) {   
     // user is scrolling to the left from image 1 to image 4   
     // reposition offset to show image 4 that is on the right in the scroll view   
     [scrollView scrollRectToVisible:CGRectMake(0,1664,320,416) animated:NO];  
    }  
    else if (scrollView.contentOffset.y == 2080) {   
     // user is scrolling to the right from image 4 to image 1   
     // reposition offset to show image 1 that is on the left in the scroll view   
     [scrollView scrollRectToVisible:CGRectMake(0,416,320,416) animated:NO];   
    } 
}