Imitation QQ Music Animation

Animation effects:

Imitation QQ Music Animation

The following analysis of animation (this analysis is certainly not unique and optimal, in fact, the implementation of this animation is not difficult):

  1. The main interface is a navigation bar controller, and the bottom toolbar settings are not hidden. Add the record button at the bottom left of the bottom toolbar
  2. Click the record button in the lower left corner, at the main interface addChildViewController
  3. On the view of the sub view controller, overlay three sub views (upper navigation bar, middle circle record cover, lower operation button)
  4. Sets the animation that appears when the view appears (the implicit animation of the overloaded layer) and sets the animation when the view exits (adds, displays, animation)

The key is the fourth step:

Set the animation when the child view appears

Sub view appears animation is realized by implicit animation overload subviews layer, layer behavior after the trigger (the layer is added to or removed from the tree layer, tree layer position, high transparency, wide change), the layer will use the following ways to find the object (the object layer response behavior comply with the CAAction agreement, as an example, provides the default behavior of CAAnimation object CALayer and applied to the layer):

  1. The actionForKey: method of the layer is called and returns the behavior object corresponding to the key value. If the corresponding key object does not exist, then the nil is returned.
  2. If the layer has a class that follows CALayerDelegate (for example: UIView), the proxy method actionForLayer:forKey: will be called
  3. Find the object of the corresponding behavior identifier (key) in the layer actions dictionary

The upper, middle, and lower three views inherit from the UIView, so you can implement the CALayerDelegate method:

/ / example (on the navigation bar) view, KCAOnOrderIn acts in the layer has been added or hidden trigger is set to NO, and the opposite is KCAOnOrderOut - (id< CAAction> actionForLayer:) (CALayer *) layer forKey: (NSString *) event{if ([event isEqualToString: kCAOnOrderIn]) {CAKeyframeAnimation *animation [CAKeyframeAnimation = animation]; animation.keyPath = @ "position; animation.duration = 0.2; animation.values = @[[NSValue valueWithCGPoint:CGPointMake ([UIScreen mainScreen].bounds.size.width/ 2, -52), [NSValue valueWithCGPoint:CGPointMake ([UIScreen mainScreen].bounds.size.width/2, 42), [NSValue (valueWithCGPoint:CGPointMake [UIScreen main Screen].bounds.size.width/2, 32] []; return animation;}

Two sets the animation when the child view exits

Originally wanted to comply with the CALayerDelegate protocol, returned to the KCAOnOrderOut behavior object to achieve, but temporarily no effect. You can only send notifications by sending notifications before the child view controller is remove, allowing the upper and lower view to add display animations to implement

- (void) disapperAnimation{CAKeyframeAnimation *animation [CAKeyframeAnimation = animation]; animation.keyPath = @ "position"; animation.duration = 0.2; animation.delegate = self; animation.values = @[[NSValue valueWithCGPoint:CGPointMake ([UIScreen mainScreen].bounds.size.width/2, 32), [NSValue valueWithCGPoint:CGPointMake ([UIScreen mainScreen].bounds.size.width/2, 42), [NSValue valueWithCGPoint:CGPointMake ([UIScreen mainScreen].bounds.size.width/2 -52)], [self.layer addAnimation:animation]; forKey:nil];}