在iOS中一个UIImageView动画之间的延迟 [英] Delay between animations on a UIImageView in iOS

查看:820
本文介绍了在iOS中一个UIImageView动画之间的延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由图像阵列的动画,关于这一点我再运行

I have an animation which is made up of an array of images, on which I then run

[myUIImageView startAnimating]

我希望动画运行一次,然后停3秒,然后重复。

我需要在一个单独的线程中运行这个动画,所以我有

I need to run this animation in a separate thread so I have

NSThread *animationThread = [[NSThread alloc] initWithTarget:self selector:@selector(startAnimTask) withObject:nil waitUntilDone:NO]; 
[animationThread start];

在我viewDidLoad中,然后

in my viewDidLoad, and then

-(void) startAnimTask {

   //create array of images here; animationDuration (3) and animationRepeatCount (1)
   [self setUpAnimation];

   while (true){
       [myUIImageView startAnimating];
       usleep(3);        
       [myUIImageView stopAnimating];
       usleep(3);    
   }
}

使用这个方法,我收到一个内存警告。我也尝试运行的开始和停止对MainThread没有运气。

Using this method, I receive a memory warning. I've also tried running the start and stop on the MainThread with no luck.

任何想法?

推荐答案

做到这一点:

 [myUIImageView startAnimating];
 [self performSelector:@selector(startAnimTask) 
         withObject:nil 
         afterDelay:(myUIImageView.animationDuration+3.0)];

现在选择的是:

 -(void)startAnimTask
 {
   [myUIImageView startAnimating];
   //repeat again then add above selector code line here
 }

这篇关于在iOS中一个UIImageView动画之间的延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆