开发者

animation starts when tilting

开发者 https://www.devze.com 2022-12-18 01:31 出处:网络
i like to start this animat开发者_Go百科ion when tilting. it doesn\'t, so i suppose some essential code is missing. please help:

i like to start this animat开发者_Go百科ion 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];
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号