An idea of animation and an idea of Animation

Source: Internet
Author: User

An idea of animation and an idea of Animation

GitHub saw a good animation https://github.com/KittenYang/KYBezierBounceView did not look at his code before, I thought for a long time how to achieve this effect: this Blue view after pulling is an irregular shape, although only one side is irregular, but it cannot be directly done with frame Animation, we can only use CAShapeLayer to draw the shape by ourselves. To draw a shape like this, you cannot use the convenient class method provided by UIBezierPath to draw images. You can only use the Path construction Method to draw images. However, if you use the Path construction Method to draw images, it is troublesome to do the animation, because the animation of the path is not very well controlled, only write the initial value and the final value of the path, and do not know how the system will interpolation the animation; here, because only one side is moving, we can still control it. The remaining problem is how to make the animation change with the gesture. In this case, you can only write a function that uses displacement as the parameter to generate the whole beiser curve at that time .... Then set the path with the amount of gesture movement. The problem is solved, but the implementation is troublesome... Therefore, this solution is only in the theoretical stage. Then I read the author's code and found that his implementation is much simpler than I thought: overwrite a CAShaperLayer on the Blue view and set the fill color to another color, then, you only need to write the besell curve on the dynamic side! This effect looks like you are dragging a side of a rectangle, but in fact you just dragged a line outside the screen, drag a new layer to overwrite the original view. The same effect looks exactly the same, but the difficulty of implementing the method is much worse. Consider another example: http://www.cnblogs.com/Phelthas/p/4523328.html made me discover a seemingly simple but easy-to-ignore fact that the animation effects that the eyes see can be achieved in a way different or even totally different from what it looks like, and it may be easier to implement ~~ For example, the animation mentioned above looks like dragging a Blue view is actually a layer that you cannot see after dragging it... In addition, iOS7 provides the UIView spring Animation: + (void) duration :( NSTimeInterval) duration delay :( NSTimeInterval) delay duration :( CGFloat) dampingRatio duration :( CGFloat) velocity options :( UIViewAnimationOptions) options animations :( void (^) (void) animations completion :( void (^) (BOOL finished) completion NS_AVAILABLE_IOS (7_0 ); however, for path animation, it seems that keyFrameAnimation must be used. Specifically, several key frames of the keyFrame animation must be set. KeyFrameAnimation. values = @ [(id) path1, (id) path2, (id) path3, (id) path4, (id) path5, (id) path1]; where path1, path2... The location of the layer of the key frames. IOS7 also provides a new Key Frame Animation api: + (void) duration :( NSTimeInterval) duration delay :( NSTimeInterval) delay options :( UIViewKeyframeAnimationOptions) options animations :( void (^) (void )) animations completion :( void (^) (BOOL finished) completion NS_AVAILABLE_IOS (7_0 );
+ (Void) addKeyframeWithRelativeStartTime :( double) frameStartTime relativeDuration :( double) frameDuration animations :( void (^) (void) animations NS_AVAILABLE_IOS (7_0 ); // start time and duration are values between 0.0 and 1.0 specifying time and duration relative to the overall time of the keyframe animation must be used in combination. Example: [UIViewanimateKeyframesWithDuration: 0.25 delay: 0 options: UIViewKeyframeAnimationOptionCalculationModeCubic animations: ^ {[UIView addKeyframeWithRelativeStartTime: 0.0 relativeDuration: 2/3. 0 animations: ^ {
Self. label. transform = CGAffineTransformMakeScale (1.5, 1.5 );
}];
[UIView addKeyframeWithRelativeStartTime: 2/3. 0 relativeDuration: 1/3. 0 animations: ^ {self. label. transform = CGAffineTransformMakeScale (1.0, 1.0);}];
} Completion: ^ (BOOL finished ){
}]; The method inside is to add a key frame. startTime and duration are both relative to the outer Duration time from 0 to 1. Note that both parameters are decimal, direct 1/2 is not acceptable !!!
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.