OC, oc Language
Overview
Introduction
- CAAnimationGroup is also called a group animation or animation group.
- Place multiple animations in an animation group and assign them to the animation attributes of the layer. All animations in the animation group are concurrently executed.
Notes
- The animation in the animation Group will not be compressed, and the part beyond the animation duration will be cut off
- The delegate and removedOnCompletion attributes of the animation in the animation group will be ignored.
- The removedOnCompletion attribute is ignored, and the animation end layer is restored to the State before the animation.
Unique attributes of CAAnimationGroup
Animations (NSArray *)
- Stores all concurrently executed animations
- The array element is a subclass of CAAnimation.
Example
Implementation
- Create an animation group object group
- Create multiple CABasicAnimation objects, which have different functions and failed attributes.
- Assign multiple basic animation objects to the group's animations attribute.
- Add an animation group to the layer where the animation is to be executed
- Use implicit animation to change the background color of a Layer
Steps
- Create a UIView control on the storyboard and have it. Modify its class attribute to a subclass of the custom UIView.
@property (weak, nonatomic) IBOutlet UIView *redView;
- Create an animation Group
// Create an animation group Object CAAnimationGroup * group = [CAAnimationGroup animation]; // set the animation group execution time group. duration = 1.0; // create a basic animation object for scaling CABasicAnimation * scale = [CABasicAnimation animation]; scale. keyPath = @ "transform. scale "; scale. fromValue =@1.0; scale. toValue = @ 0.5; // create a basic animation object to rotate CABasicAnimation * rotation = [CABasicAnimation animation]; rotation. keyPath = @ "transform. rotation "; rotation. toValue = @ (arc4random_uniform (M_PI * 2); // creates a basic animation object to modify the position CABasicAnimation * position = [CABasicAnimation animation]; position. keyPath = @ "position"; position. toValue = [NSValue valueWithCGPoint: CGPointMake (arc4random_uniform (200) + 20, arc4random_uniform (200) + 20)]; // Add the basic animation to the animation group. animations = @ [scale, rotation, position];
- Add an animation group to the layer where the animation is to be executed
[self.redView.layer addAnimation:group forKey:nil];
- Use implicit animation to change the background color of a layer
self.redView.layer.backgroundColor = [self randomColor].CGColor;
// Return random color-(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];}