在iPhone中将图像从左向右移动为圆形和无限动画(如广告)

时间:2012-09-04 09:52:54

标签: iphone animation uiimageview

我无法将图像从左向右移动。 现在我有一个情况,当我有一个无限的动画,但它只是将当前图像替换为另一个。

这是我的代码:

-(void)startAnimationTest
{
   image.animationImages = [NSArray arrayWithObjects:
                         [UIImage imageNamed:@"pic_1.png"],
                         [UIImage imageNamed:@"pic_2.png"],
                         [UIImage imageNamed:@"pic_3.png"], nil];
   [image setAnimationDuration:1];
   image.animationDuration = 4;
   [image startAnimating];

}

谢谢,

伊丽莎

1 个答案:

答案 0 :(得分:0)

尝试将图像添加到滚动视图,然后根据其内容偏移设置动画滚动视图。请参阅附带的示例代码。确保添加一个nstimer来重复调用该函数。

- (void) animateScrollView: (id) sender
{
     [UIView beginAnimations:nil context:NULL];
     CGPoint contentOffset = scrollView.contentOffset;
     contentOffset.x +=3;
     [scrollView setContentOffset:contentOffset animated:NO];
     [UIView commitAnimations];
     if (scrollView.contentOffset.x == (scrollView.bounds.size.width * 5)) {
         scrollView.contentOffset = CGPointMake(0, scrollView.bounds.origin.y);
     }
}

设置计时器如下:

    [NSTimer scheduledTimerWithTimeInterval: .03
                                 target: self
                               selector: @selector(animateScrollView:)
                               userInfo: nil
                                repeats: YES];

就是这样。希望它有所帮助。

相关问题