【问题标题】:Move image from left to right in iPhone as circular and Infinite animation (like an advertisement)在 iPhone 中将图像从左向右移动为圆形和无限动画(如广告)
【发布时间】:2012-08-28 23:04:55
【问题描述】:

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

这是我的代码:

-(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];

}

谢谢你,

伊丽莎

【问题讨论】:

  • 您的代码甚至不会尝试移动图像(甚至是什么类) - 只是初始化一组变量。
  • 对,我是 iphone 新手,我很乐意为您提供好的建议。也许你有一个很好的教程或者可以给我一个例子?

标签: iphone animation uiimageview


【解决方案1】:

尝试将图像添加到滚动视图,然后根据其内容偏移量为滚动视图设置动画。请参阅随附的示例代码。确保添加一个 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];

就是这样。希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-30
    相关资源
    最近更新 更多