//
// ViewController.m
// 核心动画CoreAnimation
//
// Created by 陆巧怡 on 15/7/29.
// Copyright (c) 2015年 Simon. All rights reserved.
//
#import "ViewController.h"
#warning CABasicAnimation\
通过设定起始点,终点,时间,动画会沿着你这设定点进行移动。可以看做特殊的CAKeyFrameAnimation
#warning CAKeyframeAnimation\
Keyframe顾名思义就是关键点的frame,你可以通过设定CALayer的始点、中间关键点、终点的frame,时间,动画会沿你设定的轨迹进行移动
#warning CAAnimationGroup\
Group也就是组合的意思,就是把对这个Layer的所有动画都组合起来。PS:一个layer设定了很多动画,他们都会同时执行,执行顺序还没有理清楚
#warning CATransition\
这个就是苹果帮开发者封装好的一些动画
#warning 基本动画 只可以改变toValue,fromValue,buyValue 这三个属性 所以是有弊端的
/*
animationWithKeyPath的值:
transform.scale = 比例轉換
transform.scale.x = 闊的比例轉換
transform.scale.y = 高的比例轉換
transform.rotation.z = 平面圖的旋轉
opacity = 透明度
margin
zPosition
backgroundColor 背景颜色
cornerRadius 圆角
borderWidth
bounds
contents
contentsRect
cornerRadius
frame
hidden
mask
masksToBounds
opacity
position
shadowColor
shadowOffset
shadowOpacity
shadowRadius
*/
@interface ViewController ()
@property (nonatomic, strong) CALayer *layer;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.layer = [CALayer layer];
self.layer.bounds = CGRectMake(0, 0, 100, 100);
self.layer.position = CGPointMake(200, 200);
self.layer.anchorPoint = CGPointMake(0, 0);
self.layer.backgroundColor = [UIColor yellowColor].CGColor;
[self.view.layer addSublayer:self.layer];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
}
#warning 创建核心动画 移动
-(void)text1{
//1.创建核心动画
CABasicAnimation *anima = [CABasicAnimation animation];
//1.1告诉系统要执行什么样的动画。通过KVC告诉系统要执行什么动画
anima.keyPath = @"position";
//从哪
//anima.fromValue = [NSValue valueWithCGPoint:CGPointMake(0, 0)];
//到哪(到指定的位置)
//anima.toValue = [NSValue valueWithCGPoint:CGPointMake(200 , 300)];
//在当前位置的基础上增加多少
//anima.byValue = [NSValue valueWithCGPoint:CGPointMake(0, 100)];
//在position的基础上增加
//anima.byValue = [NSValue valueWithCGSize:CGSizeMake(200, 200)];
//设置动画时间
anima.duration = 5.0;
//1.2 设置动画执行完毕之后不删除动画
anima.removedOnCompletion = NO;
//1.3 设置保存动画的最新状态
anima.fillMode = kCAFillModeForwards;
//2.添加核心动画到Layer
[self.layer addAnimation:anima forKey:nil];
}
#warning 创建核心动画 放大 缩小
-(void)text2{
//1.创建核心动画
CABasicAnimation *anima = [CABasicAnimation animation];
//1.1告诉系统要执行什么样的动画。通过KVC告诉系统要执行什么动画
anima.keyPath = @"bounds";
anima.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 200, 200)];
//设置动画时间
anima.duration = 1.0;
//1.2 设置动画执行完毕之后不删除动画
anima.removedOnCompletion = NO;
//1.3 设置保存动画的最新状态
anima.fillMode = kCAFillModeForwards;
//2.添加核心动画到Layer
[self.layer addAnimation:anima forKey:nil];
}
#warning 创建核心动画 旋转
-(void)text3{
//1.创建核心动画
CABasicAnimation *anima = [CABasicAnimation animation];
//1.1告诉系统要执行什么样的动画。通过KVC告诉系统要执行什么动画
anima.keyPath = @"transform";
//CATransform3DMakeRotation 第一个参数是旋转角度(亦可以通过计算填写弧度值),后面三个参数形成一个围绕其旋转的向量,起点位置由UIView的center属性标识。
//旋转角度 是由角度值装化为弧度值。计算公式为:Mπ/180 。M代表是旋转的角度。
anima.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0.78, 0, 0, 1)];
//设置动画时间
anima.duration = 1.0;
#if 0 //这个效果跟上面的效果一样
anima.keyPath = @"transform.rotation.z";
anima.toValue = @(0.78);
#endif
//1.2 设置动画执行完毕之后不删除动画
anima.removedOnCompletion = NO;
//1.3 设置保存动画的最新状态
anima.fillMode = kCAFillModeForwards;
//2.添加核心动画到Layer
[self.layer addAnimation:anima forKey:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
基本动画CoreAnimation
最新推荐文章于 2024-08-20 20:20:20 发布