标签:
简介
注意事项
animations(NSArray *)
效果图
实现思路
实现步骤
@property (weak, nonatomic) IBOutlet UIView *redView;
//创建动画组对象
CAAnimationGroup *group = [CAAnimationGroup animation];
//设置动画组的执行时间
group.duration = 1.0;
//创建基本动画对象,用来进行缩放
CABasicAnimation *scale = [CABasicAnimation animation];
scale.keyPath = @"transform.scale";
scale.fromValue = @1.0;
scale.toValue = @0.5;
//创建基本动画对象,用来进行旋转
CABasicAnimation *rotation = [CABasicAnimation animation];
rotation.keyPath = @"transform.rotation";
rotation.toValue = @(arc4random_uniform(M_PI * 2));
//创建基本动画对象,用来修改位置
CABasicAnimation *position = [CABasicAnimation animation];
position.keyPath = @"position";
position.toValue = [NSValue valueWithCGPoint:CGPointMake(arc4random_uniform(200) + 20, arc4random_uniform(200) + 20)];
//将基本动画添加到动画组中
group.animations = @[scale, rotation, position];
[self.redView.layer addAnimation:group forKey:nil];
self.redView.layer.backgroundColor = [self randomColor].CGColor;
//返回随机颜色
- (UIColor *)randomColor
{
return [UIColor colorWithRed:arc4random_uniform(255) / 255.0 green:arc4random_uniform(255) / 255.0 blue:arc4random_uniform(255) / 255.0 alpha:1.0];
}
标签:
原文地址:http://www.cnblogs.com/funny11/p/4970349.html