2013-03-28 65 views
0

我試圖在設備處於縱向模式時使圖像水平向右滾動。圖像需要自動滾動,直到計時器結束,並需要無縫滾動。我怎樣才能做到這一點?無限滾動圖像;以縱向模式從左到右滾動

+0

到目前爲止你有什麼? – danh 2013-03-28 02:34:12

+0

並排顯示該圖像的三個實例(A,B,C)。一旦實例C變得可見,將實例A右移到C(B,C,A)....等等。 – Till 2013-03-28 03:11:24

回答

1

試試這個,希望這會有所幫助。

// Create Image's array 

    NSMutableArray * imagesArray = [[NSMutableArray alloc]init]; 
    for (int imageCount = 0; imageCount < YOURCOUNT;imageCount++) 
    { 
     [imagesArray addObject:[UIImage imageNamed:@"localImagePath%d.png",imageCount]]; 
    } 
// Create ScrollView  

    UIScrollView * scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0.0,0.0,320.0,480.0)]; 
    scrollview.contentSize = CGSizeMake(scrollview.frame.size.width * YOURCOUNT,scrollview.frame.size.height); 

// Add those image's to the scrollview 

    CGFloat xPos = 0.0; 
    for (UIImage * image in imagesArray) { 
    @autoreleasepool { 
     UIImageView * imageview = [[UIImageView alloc]initWithImage:image]; 
     imageview.frame = CGRectMake(xPos, 0.0,scrollview.frame.size.width,scrollview.frame.size.height); 
        [scrollview addSubview:imageview]; 
        xPos += scrollview.frame.size.width; 
     } 
    } 

    [self.view addSubview:scrollview]; 

// Animate to the Right 

    [UIView animateWithDuration:10.0 delay:0 options:UIViewAnimationTransitionNone 
          animations:^{ 
           [scrollview setContentOffset:CGPointMake(scrollview.contentSize.width - scrollview.frame.size.width,0.0) animated:NO]; 
          } 
          completion:^(BOOL finished) { 
           NSLog(@"Finished"); 
          }];