IOS learning-draw an automatically rotated circle with an edge gradient color

Source: Internet
Author: User

Practice it before writing it!

I have never been familiar with Ca, and it is still quite difficult for me.

The transition time is a little long.

In the middle, there are other tasks with higher priority than the HUD I want to do. So I 've been dragging it on until now.

It took me two days to learn about ca animation, find code on the Internet, and paste code. Then I learned how to use it ......

It's done.

This process has benefited a lot! Not only have I learned

Calayer

Cabasicanimation

Also try to customize a layer and then operate the layer to complete the animation.

The results are good.

Paste some code to the animation functions for the effects such as layer rotation and opacity!

// Back to the essential question: How can I draw an automatically rotated circle with an edge gradient color!
This function can help you solve the problem. Use a gradient color circle as your layer chart. That is, the image you want to rotate. Then you can call this function and turn it...
This is really the simplest and most practical method I have found.
 
//rotation animation- (void) runSpinAnimationOnView:(CALayer*)layerToAnimate duration:(CGFloat)duration rotations:(CGFloat)rotations repeat:(float)repeat;{    CABasicAnimation* rotationAnimation;    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ];    rotationAnimation.duration = duration;    rotationAnimation.cumulative = YES;    rotationAnimation.repeatCount = repeat;    [layerToAnimate addAnimation:rotationAnimation forKey:@"rotationAnimation"];}
// Your layer can be a graph and then flash by adjusting the transparency (of course there must be another way) // Flash animation-(void) opacityforever_animation :( float) time withlayer :( calayer *) layer {cabasicanimation * animation = [cabasicanimation animationwithkeypath: @ "opacity"]; animation. fromvalue = [nsnumber numberwithfloat: 1.0]; animation. tovalue = [nsnumber numberwithfloat: 0.5]; animation. autoreverses = yes; animation. duration = time; animation. repeatcount = flt_max; animation. removedoncompletion = no; animation. fillmode = kcafillmodeforwards; [layer addanimation: animation forkey: @ "opacity"];}-(void) moveduration :( float) Time fromoffset :( float) fromvalue withoffsetx :( float) X withlayer :( calayer *) layer {cabasicanimation * animation = [cabasicanimation animationwithkeypath: @ "transform. translation. X "]; animation. fromvalue = [nsnumber numberwithfloat: fromvalue]; animation. tovalue = [nsnumber numberwithfloat: X]; animation. duration = time; animation. removedoncompletion = no; animation. fillmode = kcafillmodeforwards; [layer addanimation: animation forkey: @ "transform. translation. X "];}

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.