-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
  • 8,153
  • 7
  • 49
  • 61

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
  • 38,095
  • 11
  • 81
  • 132
1

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

MANIAK_dobrii
  • 6,014
  • 3
  • 28
  • 55
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,982
  • 6
  • 52
  • 96
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
  • 129,200
  • 40
  • 280
  • 281
ASP
  • 88
  • 5