0

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

4

1 回答 1

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");
                             }];
于 2013-03-28T03:37:05.780 回答