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" ]; } |
利用陀螺儀實現更真實的微信搖一搖動畫
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.