views:

47

answers:

1

i like to start this animation when tilting. it doesn't, so i suppose some essential code is missing. please help:

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
 flap.animationImages = [NSArray arrayWithObjects:
       [UIImage imageNamed: @"ronnie1.png"],
       [UIImage imageNamed: @"ronnie2.png"],
       [UIImage imageNamed: @"ronnie3.png"],
       [UIImage imageNamed: @"ronnie4.png"], 
       [UIImage imageNamed: @"ronnie5.png"],
       [UIImage imageNamed: @"ronnie6.png"],
       [UIImage imageNamed: @"ronnie7.png"],
       [UIImage imageNamed: @"ronnie8.png"],
       [UIImage imageNamed: @"ronnie9.png"],
       [UIImage imageNamed: @"ronnie10.png"],nil];
 [flap setAnimationRepeatCount:1];
 flap.animationDuration = 2;
 [flap startAnimating];
}
A: 

As named, -accelerometer:didAccelerate: will be fired whenever the accelerometer detects a change in acceleration. Hence, during your tilting probably this method will be executed dozens of times. But every time it is executed, you reset the animation, so the net effect is as if no animation happened.

You have to (1) analyze the acceleration to check whether it is really tilting, and (2) check [flap isAnimating] and don't reset the animation if YES.

KennyTM