常見的可執行隱式動畫的屬性
位置與尺寸
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];}
實現效果
新聞熱點
疑難解答