2013-03-28 34 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"); 
          }];