layer动画。
CABasicAnimation--对应android 属性动画。
//透明动画。
CABasicAnimation * animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.beginTime = CACurrentMediaTime()+3;//开始时间
animation.fromValue = @1.0;//开始值。 animation.toValue = @0.1;//结束值 animation.duration = 2.0f;//时长 animation.fillMode = kCAFillModeBackwards;//填充模式 self.myLabel.layer addAnimation:animation forKey:@"opacity" ];
可设置参数:1.时长。2反向播放3.开始时间 。4.重复次数。5.重复播放间隔。6.快慢。7.播完后行为。留在那里还是移除。
/* The begin time of the object, in relation to its parent object, if * applicable. Defaults to 0. */ @property CFTimeInterval beginTime; 从什么时候开始执行动画。 /* The basic duration of the object. Defaults to 0. */ //动画时长 @property CFTimeInterval duration; /* The rate of the layer. Used to scale parent time to local time, e.g. * if rate is 2, local time progresses twice as fast as parent time. * Defaults to 1. */ //执行时,相对速度。 @property float speed; /* Additional offset in active local time. i.e. to convert from parent * time tp to active local time t: t = (tp - begin) * speed + offset. * One use of this is to "pause" a layer by setting `speed' to zero and * `offset' to a suitable value. Defaults to 0. */ @property CFTimeInterval timeOffset; /* The repeat count of the object. May be fractional. Defaults to 0. */ @property float repeatCount;//重复次数 /* The repeat duration of the object. Defaults to 0. */ @property CFTimeInterval repeatDuration;//多入后重播。 /* When true, the object plays backwards after playing forwards. Defaults * to NO. */ @property BOOL autoreverses;//自动反向播放 /* Defines how the timed object behaves outside its active duration. * Local time may be clamped to either end of the active duration, or * the element may be removed from the presentation. The legal values * are `backwards', `forwards', `both' and `removed'. Defaults to * `removed'. */ @property(copy) CAMediaTimingFillMode fillMode;//填充模式 @end /* `fillMode' options. */ CA_EXTERN CAMediaTimingFillMode const kCAFillModeForwards//执行填充。动画结束在哪儿就在哪儿。必须是不移除动画。 API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)); CA_EXTERN CAMediaTimingFillMode const kCAFillModeBackwards//执行前就填充到相应位置或状态。 API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)); CA_EXTERN CAMediaTimingFillMode const kCAFillModeBoth API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)); CA_EXTERN CAMediaTimingFillMode const kCAFillModeRemoved API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0));
常用属性:
一些常用的animationWithKeyPath值
值 | 说明 | 使用形式 |
---|---|---|
transform.scale | 比例转化 | @(0.8) |
transform.scale.x | 宽的比例 | @(0.8) |
transform.scale.y | 高的比例 | @(0.8) |
transform.rotation.x | 围绕x轴旋转 | @(M_PI) |
transform.rotation.y | 围绕y轴旋转 | @(M_PI) |
transform.rotation.z | 围绕z轴旋转 | @(M_PI) |
cornerRadius | 圆角的设置 | @(50) |
backgroundColor | 背景颜色的变化 | (id)[UIColor purpleColor].CGColor |
bounds | 大小,中心不变 | [NSValue valueWithCGRect:CGRectMake(0, 0, 200, 200)]; |
position | 位置(中心点的改变) | [NSValue valueWithCGPoint:CGPointMake(300, 300)]; |
contents | 内容,比如UIImageView的图片 | imageAnima.toValue = (id)[UIImage imageNamed:@"to"].CGImage; |
opacity | 透明度 | @(0.8) |
contentsRect.size.width | 横向拉伸缩放 | @(0.4)最好是0~1之间的 |
基本和android 一样一样的。