OC, oc Language
Introduction
Example
Create a UIView object through storyboard and own the object
@property (weak, nonatomic) IBOutlet UIView *blueView;
Click on the screen to dynamically modify the animation properties of the layer.
-(Void) touchesBegan :( NSSet *) touches withEvent :( UIEvent *) event {// generate a random rotation angle using a random number CGFloat angle = angleToRadion (arc4random_uniform (360) + 1 ); // rotate self. blueView. layer. transform = CATransform3DMakeRotation (angle, 0, 0, 1); // move to a random position (50 ~ 249, 50 ~ 449) self. blueView. layer. position = CGPointMake (arc4random_uniform (200) + 50, arc4random_uniform (400) + 50); // set the random radius of the rounded corner self. blueView. layer. cornerRadius = arc4random_uniform (50); // set the random background color self. blueView. layer. backgroundColor = [self randomColor]. CGColor; // set the random Border Width self. blueView. layer. borderWidth = arc4random_uniform (10); // set the random border color self. blueView. layer. borderColor = [self randomColor]. CGColor ;}
Method for generating random colors
- (UIColor *)randomColor{return [UIColor colorWithRed:arc4random_uniform(256) / 255.0 green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) / 255.0 alpha:1];}
Effect