Coretext a little improvement in the animation of wonderful text contour drawing

Source: Internet
Author: User

Panda Pig • Patty original or translated works. Welcome reprint, Reprint please indicate the source.
If you feel that the writing is not good please more advice, if you feel good please support a lot of praise. Thank you! Hopy;)

Original text in:

http://oleb.net/blog/2010/12/animating-drawing-of-cgpath-with-cashapelayer/

The principle is explained in:

Http://www.codeproject.com/Articles/109729/Low-level-text-rendering

The article is very well written and recommended for everyone to read.

But its source code run a little bit of a problem, that is, sometimes the brush display does not come out!

There is no problem when you draw the graphics for the first time, but sometimes the brushes do not appear when you switch to the text outline.

In-(void) Animationdidstop: (Caanimation *) Anim finished: (BOOL) flag at the next breakpoint, it is also interrupted when the view is switched (the previous animation is not completed).

Go to Startanimation method view

-(void) startanimation{[self. PathlayerRemoveallanimations];[Self. PenlayerRemoveallanimations];Self. Penlayer. Hidden= NO;Cabasicanimation *pathanimation = [Cabasicanimation animationwithkeypath:@"Strokeend"];Pathanimation. Duration=10.0;Pathanimation. Fromvalue= [NSNumber numberwithfloat:0.0F;Pathanimation. Tovalue= [NSNumber numberwithfloat:1.0F;[Self. PathlayerAddanimation:pathanimation forkey:@"Strokeend"];Cakeyframeanimation *penanimation = [Cakeyframeanimation animationwithkeypath:@"Position"];Penanimation. Duration=10.0;Penanimation. Path= Self. Pathlayer. Path;Penanimation. Calculationmode= kcaanimationpaced;Penanimation. Delegate= Self;[Self. PenlayerAddanimation:penanimation forkey:@"Position"];}

The deletion of the original animation was found at the beginning, and the deletion of the animation also caused Animationdidstop's callback, although the author specifically enabled the display brush after deletion:

self.penLayer.hiddenNO;

However, this and the order of execution of animationdidstop are not guaranteed! If Animationdidstop is executed later, the previously mentioned brush is hidden and is not displayed.

Knowing the reason to solve it is very simple, we only need to modify the Animationdidstop method as follows:

- (void) animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{    //如果动画不是由于删除而停止的才隐藏画笔!    if (flag){        self.penLayer.hiddenYES;    }}

Now run, small bugs get repaired, cute brushes and hard work again:

A little improvement in animating Coretext text outlines

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.