常见的可执行隐式动画的属性
位置与尺寸
appearance
边框
阴影
通过storyboard创建一个UIView对象,并拥有该对象
@PRoperty (weak, nonatomic) IBOutlet UIView *blueView;
点击屏幕,动态修改图层的可动画属性
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ //通过随机数产生随机的旋转角度 CGFloat angle = angleToRadion(arc4random_uniform(360) + 1); //旋转 self.blueView.layer.transform = CATransform3DMakeRotation(angle, 0, 0, 1); //移动到随机位置(50~249, 50~449) self.blueView.layer.position = CGPointMake(arc4random_uniform(200) + 50, arc4random_uniform(400) + 50); //设置随机的圆角半径 self.blueView.layer.cornerRadius = arc4random_uniform(50); //设置随机的背景颜色 self.blueView.layer.backgroundColor = [self randomColor].CGColor; //设置随机的边框宽度 self.blueView.layer.borderWidth = arc4random_uniform(10); //设置随机的边框颜色 self.blueView.layer.borderColor = [self randomColor].CGColor;}
产生随机颜色的方法
- (UIColor *)randomColor{ return [UIColor colorWithRed:arc4random_uniform(256) / 255.0 green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) / 255.0 alpha:1];}
实现效果
新闻热点
疑难解答