美文网首页
iOS 动画实现

iOS 动画实现

作者: 曲终人散Li | 来源:发表于2016-10-11 15:07 被阅读24次

一种是UIKit动画,用于简单的动画,例如位置,大小,透明度变化等。
另一种是Core Animation动画,用于自定义,复杂的动画,可定义性强,装 B必备技能。

UIKit 提供出来的动画主要是基于UIView的:
使用方法有两种:

其中一种:
[UIView beginAnimations:@"animation" context:nil];
....
[UIView commitAnimations];

另一种:
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
} completion:^(BOOL complete){

                 }];  

Core Animation动画提供的动画略屌,大致有三类:
CABasicAnimation 基本型动画:
CABasicAnimation *animation=[CABasicAnimation animation];
[view.layer addAnimation:animation forKey:@"position"];

CAKeyframeAnimation关键帧动画,类似于flash,一帧帧连起来组成动画效果:
CAKeyframeAnimation *animation=[CAKeyframeAnimation animation];
[view.layer addAnimation:animation forKey:@"position"];

CATransitionAnimation转换动画,可以结合CGMutablePathRef来定制动画移动的轨迹:
CAKeyframeAnimation *animation=[CAKeyframeAnimation animation];
animation.path=animationPath;
[view.layer addAnimation:animation forKey:@"position"];

相关文章

网友评论

      本文标题:iOS 动画实现

      本文链接:https://www.haomeiwen.com/subject/aghbyttx.html