您的位置:首页 > 移动开发 > IOS开发

iOS简单的抖动动画效果

2015-10-13 16:31 567 查看

1 . CABasicAnimation动画举例:可以模仿iphone删除程序模式下的抖动效果:

[code]CALayer*viewLayer=[self layer];
CABasicAnimation*animation=[CABasicAnimation 

animationWithKeyPath:@"transform"];
animation.duration=0.2;
animation.repeatCount = 100000;
animation.autoreverses=YES;
animation.fromValue=[NSValue valueWithCATransform3D:CATransform3DRotate

(viewLayer.transform, -0.03, 0.0, 0.0, 0.03)];
animation.toValue=[NSValue valueWithCATransform3D:CATransform3DRotate

(viewLayer.transform, 0.03, 0.0, 0.0, 0.03)];
[viewLayer addAnimation:animation forKey:@"wiggle"];


#

实现iphone漂亮的动画效果主要有两种方法,一种是UIView层面的,一种是使用CATransition进行更低层次的控制,

第一种是UIView,UIView方式可能在低层也是使用CATransition进行了封装,它只能用于一些简单的、常用的效果展现,这里写一个常用的示例代码,供大家参考。

[code][UIView beginAnimations:@"Curl"context:nil];//动画开始
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp 

forView:myview cache:YES];
[myview removeFromSuperview];
[UIView commitAnimations];


注意 : 第二种方式相对复杂一些,但如果更好的进行控制,还是使用这种方法吧,基本使用方法可以看一下如下例子:

[code]CATransition *animation = [CATransition animation];
[animation setDuration:1.25f];
[animation setTimingFunction:[CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseIn]];
[animation setType:kCATransitionReveal];
[animation setSubtype: kCATransitionFromBottom];
[self.view.layer addAnimation:animation forKey:@"Reveal"];
还有一种设置动画类型的方法,不用setSubtype,只用setType
[animation setType:@"suckEffect"];


这里的suckEffect就是效果名称,可以用的效果主要有:

pageCurl 向上翻一页

pageUnCurl 向下翻一页

rippleEffect 滴水效果

suckEffect 收缩效果,如一块布被抽走

cube 立方体效果

oglFlip 上下翻转效果
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: