利用陀螺儀實現更真實的微信搖一搖動畫

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*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{    
//想搖你的手機嘛?就寫在這,然後,然後,沒有然後了
application.applicationSupportsShakeToEdit=YES;
}
-(void)motionEnded:(UIEventSubtype)motionwithEvent:(UIEvent*)event {
if(motion==UIEventSubtypeMotionShake) {
// 真實一點的搖動動畫
[selfaddAnimations];
// 播放聲音
AudioServicesPlaySystemSound(soundID);
}
}
- (void)addAnimations {
CABasicAnimation*translation = [CABasicAnimationanimationWithKeyPath:@"transform"];
translation.timingFunction= [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
translation.toValue=[NSValuevalueWithCATransform3D:CATransform3DMakeRotation(-M_PI_4, 0, 0, 100)];
translation.duration= 0.2;
translation.repeatCount= 2;
translation.autoreverses= YES;
[shake.layeraddAnimation:translationforKey:@"translation"];
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章