核心動畫
特點 1. 自己去 自己可以回來
2. 動畫移動的圖層, 真實的位置 沒有改變
CALayer
基本屬性
backergroundColor 背景顏色 [UIColor redColor].CGColor
anchorPoint 錨點CGPoint
值得范圍是0到1之間
position 位置 CGPoint
bounds 大小 CGRect
opacity 透明度
contents 內容id類型
其他屬性
邊框
borderWidth 邊框寬度
borderColor 邊框顏色
陰影
shadowColor 陰影顏色
shadowOffset 陰影位置
shadowRadius 陰影半徑
==需要設置陰影的透明度==
shadowOpacity 陰影透明度
圓角
cornerRadius 設置圓角
masksToBounds 周圍的遮罩 ==如果去掉遮罩那么陰影效果就不會顯示==
隱式動畫
自帶隱式動畫,不過可以手動關閉
[CATransaction begin]; 開啟事務
[CATransaction setDisableActions:YES]; 關閉動畫
[CATransaction commit]; 提交事物
Transform屬性
self.layer.transform = CATransform3DTranslate(self.layer.transform, 30, 0, 0); 平移
self.layer.transform = CATransform3DScale(self.layer.transform, 0.5, 0.5, 0); 縮放
self.layer.transform = CATransform3DRotate(self.layer.transform, M_PI_4, 1, 1, 1); 旋轉
基本動畫(CABasicAnimation)
因為是NSOBjiet的分類所以不需要設置代理
repeatCount 循環次數
duration 單次運行完畢所需時間
Position(X軸 Y軸)
CABasicAnimation *basic = [CABasicAnimation animationWithKeyPath:@"position.y"],
key:表示你想讓它產生那個屬性的動畫, position界面的移動使用
basic.toValue = [NSValue valueWithCGPoint:CGPointMake(200, 500)]; 移動的位置
basic.removedOnCompletion = NO; 到了那個移動位置后,是否返回
basic.fillMode = kCAFillModeForwards; 動畫的階段模式,在動畫還沒開始前 和上面的一起搭配使用,固定用法
Transform(Rotation And Scale)
CABasicAnimation *basic = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 旋轉
basic.toValue = @(M_PI * 2.5); 設置屬性 即旋轉的角度
[self.layer addAnimation:basic forKey:nil]; 需要添加到layer上面
CABasicAnimation *basic = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; 縮放
basic.toValue = @(0.5); 設置屬性
basic.repeatCount = MAXFLOAT;
basic.duration = 2.0;
[self.layer addAnimation:basic forKey:nil]; 添加
關鍵幀動畫(CAKeyframeAnimation)
Values 屬性可以包含多個動作
Path 屬性可以設置他的移動路徑
沿著固定的點進行移動
CAKeyframeAnimation *key = [CAKeyframeAnimation animationWithKeyPath:@"position"];
//設置屬性
NSValue *value1 = [NSValue valueWithCGPoint:CGPointMake(30, 30)];
NSValue *value2 = [NSValue valueWithCGPoint:CGPointMake(30, 500)];
NSValue *value3 = [NSValue valueWithCGPoint:CGPointMake(360, 500)];
NSValue *value4 = [NSValue valueWithCGPoint:CGPointMake(360, 30)];
key.values = @[value1,value2,value3,value4,value1];
key.repeatCount = MAXFLOAT;
key.duration = 3.0;
//2.添加
[self.layer addAnimation:key forKey:nil];
沿繪制路徑移動
CAKeyframeAnimation *key = [CAKeyframeAnimation animationWithKeyPath:@"position"];
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(30, 400, 100, 300)];
key.path = path.CGPath;
key.duration = 2.0;
//2.添加
[self.layer addAnimation:key forKey:nil];
平面的抖動 (通過旋轉實現)
CAKeyframeAnimation *key = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];
key.values = @[@(-M_PI_4 * 0.03),@(M_PI_4 * 0.03),@(M_PI_4 * 0.03)];
key.repeatCount = 30;
//2.添加
[self.layer addAnimation:key forKey:nil];
轉場動畫(CATransition)
CATransition *sition = [CATransition animation];
//設置屬性
//樣式
sition.type = kCATransitionMoveIn;
//方向
sition.subtype = kCATransitionFromBottom;
[self.myImageView.layer addAnimation:sition forKey:nil];
組動畫(CAAnimationGroup)
//1.創建動畫對象
CAAnimationGroup *group = [CAAnimationGroup animation];
//1.創建動畫
CAKeyframeAnimation *key = [CAKeyframeAnimation animationWithKeyPath:@"position"];
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(30, 300, 300, 200)];
key.path = path.CGPath;
//1.創建動畫對象
CABasicAnimation *basic = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
//設置屬性
basic.toValue = @(0.1);
//1.旋轉
//1.創建動畫 基本動畫 transform.rotation 默認是繞著Z軸
CABasicAnimation *basic1 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
//設置屬性
basic1.toValue = @(M_PI * 10);
//包含多個動畫對象
group.animations = @[key,basic,basic1];
group.duration = 3;
group.repeatCount = 30;
//2.添加動畫
[self.layer addAnimation:group forKey:nil];
[TOC]