CABasicAnimation的属性
属性 | 说明 |
---|---|
duration | 动画时长(秒为单位)(注:此处与原文有出入) |
repeatCount | 重复次数。永久重复的话设置为HUGE_VALF。 |
beginTime | 指定动画开始时间。从开始指定延迟几秒执行的话,请设置为 「CACurrentMediaTime() + 秒数」的形式。 |
timingFunction | 设定动画的速度变化 |
autoreverses | 动画结束时是否执行逆动画 |
CABasicAnimation *animation = [CABasicAnimation animation];
//设置动画keyPath
animation.keyPath = @"position";
// 起始帧和终了帧的设定
animation.fromValue = [NSValue valueWithCGPoint:self.img.layer.position]; // 起始帧
animation.toValue = [NSValue valueWithCGPoint:CGPointMake(320, 480)]; // 终了帧
// 动画终了后不返回初始状态
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
//设置动画时间
animation.duration = 0.5;
animation.delegate = self;
//重复次数
animation.repeatCount = 2;
//添加动画都layer层上
[self.img1.layer addAnimation:animation forKey:nil];
keyPath的字段
transform.rotation.x 围绕x轴翻转 参数:角度 angle2Radian(4)
transform.rotation.y 围绕y轴翻转 参数:同上
transform.rotation.z 围绕z轴翻转 参数:同上
transform.rotation 默认围绕z轴
transform.scale.x x方向缩放 参数:缩放比例 1.5
transform.scale.y y方向缩放 参数:同上
transform.scale.z z方向缩放 参数:同上
transform.scale 所有方向缩放 参数:同上
transform.translation.x x方向移动 参数:x轴上的坐标 100
transform.translation.y x方向移动 参数:y轴上的坐标
transform.translation.z x方向移动 参数:z轴上的坐标
transform.translation 移动 参数:移动到的点 (100,100)
opacity 透明度 参数:透明度 0.5
backgroundColor 背景颜色 参数:颜色 (id)[[UIColor redColor] CGColor]
cornerRadius 圆角 参数:圆角半径 5
borderWidth 边框宽度 参数:边框宽度 5
bounds 大小 参数:CGRect
contents 内容 参数:CGImage
contentsRect 可视内容 参数:CGRect 值是0~1之间的小数
hidden 是否隐藏
position
shadowColor
shadowOffset
shadowOpacity
shadowRadius