简介
注意事项
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];}
新闻热点
疑难解答