无限滚动图像;在纵向模式下从左向右滚动

时间:2013-03-28 01:15:39

标签: iphone ios cocoa-touch

我正在尝试在设备处于纵向模式时使图像水平向右滚动。图像需要自动滚动,直到计时器结束,并且需要无缝滚动。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分: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");
                             }];