-1

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

[myUIImageView startAnimating]

I want the animation to run once, then stop for 3 seconds, then repeat.

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

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);    
   }
}

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

Any ideas?

MSpeed
  • 7,914
  • 6
  • 46
  • 57

4 Answers4

5

Do this:

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

Now selector is:

 -(void)startAnimTask
 {
   [myUIImageView startAnimating];
   //repeat again then add above selector code line here
 }
Paresh Navadiya
  • 37,791
  • 11
  • 79
  • 130
1

UI is not thread safe, so UI calls should be executed only in main thread, maybe this is the case.

MANIAK_dobrii
  • 5,945
  • 3
  • 28
  • 54
1

I think you can go with this:

  [self performSelector:@selector(startAnimTask) 
             withObject:nil 
             afterDelay:0.1];

  [self performSelector:@selector(startAnimTask) 
             withObject:nil 
             afterDelay:3.0];

In startAnimTask method write your animation logic code.

Enjoy Coding :)

Mrunal
  • 13,672
  • 6
  • 49
  • 93
1

Try this approach to complete your task:

[self performSelector:@selector(myTask) 
             withObject:nil 
             afterDelay:3.0];

-(void)myTask{

//Write your logic for animation

}
Mick MacCallum
  • 126,953
  • 40
  • 282
  • 279
ASP
  • 78
  • 5