如何循环动画和之间10秒

时间:2014-02-24 07:42:20

标签: cocoa animation

LogoAnimation.animationImages = [NSArray arrayWithObjects:如何在循环动画之间实现10秒暂停“中断”?就像第一个动画运行然后10暂停和10秒后相同的动画一次又一次。我尝试了一切,但我不确切知道如何解决它! 我的代码在这里:

ViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    LogoAnimation.animationImages= [NSArray arrayWithObjects:

                                    [UIImage imageNamed:@"TestAnimation_01"],
                                    [UIImage imageNamed:@"TestAnimation_02"],
                                    [UIImage imageNamed:@"TestAnimation_03"],
                                    [UIImage imageNamed:@"TestAnimation_04"],
                                    [UIImage imageNamed:@"TestAnimation_05"],
                                    [UIImage imageNamed:@"TestAnimation_06"], nil];


    [LogoAnimation setAnimationRepeatCount:1];
    LogoAnimation.animationDuration = 2;

    [LogoAnimation startAnimating];

    [self.view addSubview:LogoAnimation];


}

1 个答案:

答案 0 :(得分:0)

我可以假设你使用的是UIImageView,而LogoAnimation和TestAnimation实际上应该是同一个东西吗?

UIImageView没有为您提供此功能。要使用UIImageView执行此操作,您可以在阵列末尾添加更多图像,以对应同一图像的10秒。或者你可以在UIImageView上重复计数1次,并且每10秒启动一次NSTimer来启动动画。

- (void)viewDidLoad
{
    TestAnimation.animationImages= [NSArray arrayWithObjects:

                                    [UIImage imageNamed:@"TestAnimation_01"],
                                    [UIImage imageNamed:@"TestAnimation_02"],
                                    [UIImage imageNamed:@"TestAnimation_03"],
                                    [UIImage imageNamed:@"TestAnimation_04"],
                                    [UIImage imageNamed:@"TestAnimation_05"],
                                    [UIImage imageNamed:@"TestAnimation_06"], nil];


    [TestAnimation setAnimationRepeatCount:1];
    TestAnimation.animationDuration = 2;
    [TestAnimation startAnimating];
    [self.view addSubview:TestAnimation];

    // You need to add a property to your interface @property (strong) NSTimer *timer;
    self.timer = [NSTimer scheduledTimerWithTimeInterval:12.0 target:TestAnimation selector:@selector(startAnimating) userInfo:nil repeats:YES]; // 12.0 interval = 2s animation + 10s wait between.
}

- (void)dealloc {
    [self.timer invalidate];
}