利用陀螺仪实现更真实的微信摇一摇动画

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
- ( BOOL )application:( UIApplication *)application didFinishLaunchingWithOptions :( NSDictionary *)launchOptions
{    
//想摇你的手机嘛?就写在这,然后,然后,没有然后了
application .applicationSupportsShakeToEdit = YES ;
}
-( void )motionEnded:(UIEventSubtype)motion withEvent :( UIEvent *)event {
if (motion==UIEventSubtypeMotionShake) {
// 真实一点的摇动动画
[ self addAnimations ];
// 播放声音
AudioServicesPlaySystemSound (soundID);
}
}
- ( void )addAnimations {
CABasicAnimation *translation = [ CABasicAnimation animationWithKeyPath : @"transform" ];
translation .timingFunction = [ CAMediaTimingFunction functionWithName :kCAMediaTimingFunctionEaseInEaseOut];
translation .toValue =[ NSValue valueWithCATransform3D :CATransform 3 DMakeRotation(- M_PI_4 , 0 , 0 , 1 0 0 )];
translation .duration = 0 .2 ;
translation .repeatCount = 2 ;
translation .autoreverses = YES ;
[shake .layer addAnimation :translation forKey : @"translation" ];
}


你可能感兴趣的:(动画,手机,陀螺仪)