文章目录
-
- 1. iOS动画
- 2. UIView动画
- 3. CAAnimation核心动画
- 4. CABasicAnimation
- 5. CAKeyframeAnimation关键帧动画
- 6. 组动画
- 7. 贝塞尔曲线
1. iOS动画
总的来说,从涉及类的形式来看,iOS动画有:基于UIView的仿射形变动画,基于CAAnimation及其子类的动画,基于CG的动画。这篇文章着重总结前两种动画。
2. UIView动画
设置UIView形变动画有两种常见用到的属性,.frame,.transform,所以有的人也可以分别称之为:
① frame动画
② transform动画
这两种动画只需要在动画语法中适当的位置,基于UIView和CALayer的属性设置变化值即可。这种动画,不需要 调用核心动画CAAnimation里面的专用类和API。
其中,frame动画设置方式有限,必须确切地制定形变前后的frame,平移还好,特别是 旋转 的时候,只能通过数学知识计算出新的frame。这就得不偿失了。所以,更多的时候,当涉及一些frame,bounds,center的改变或是形变的时候可以用transform来取代frame。
2.1 设置UIView动画的两种语法形式
begin — commit
//偏移动画
[UIView beginAnimations:@"move" context:nil];
[UIView setAnimationDuration:2];
[UIView setAnimationDelegate:self];
imageContainView.frame = CGRectMake(80, 80, 200, 200);
[label1 setBackgroundColor:[UIColor yellowColor]];
[label1 setTextColor:[UIColor redColor]];
[UIView commitAnimations];
animations block
//缩放动画
view.transform = CGAffineTransformIdentity;
[UIView animateWithDuration:1.0f animations:^{
view.transform = CGAffineTransformMakeScale(2.0f, 2.0f);
}];
2.2 设置属性形变动画的两种类型
UIView的 CGAffineTransform 类型属性:animatedView.transform
一般是View的旋转,拉伸移动等属性,是二维的,通常使用都是前缀CGAffineTransform的类。
CGAffineTransform transform = CGAffineTransformScale(imageContainView.transform, 1.2, 1.2);
[UIView beginAnimations: @"scale"context: nil];
[UIView setAnimationDuration: 2];
[UIView setAnimationDelegate: self];
[imageView setTransform: transform];
[UIView commitAnimations];
CALayer的CATra