There are several paths to be animated. I want each to appear when the user 
does some action. It seemed the best to but them in a method called by drawRect 
and redraw the view when something changed. Why would the memory footprint be 
enlarged?

thanks for pointing to didMoveToWindow.

David



On Oct 23, 2012, at 1:25 PM, David Duncan <[email protected]> wrote:

> 
> On Oct 23, 2012, at 12:34 PM, David Rowland <[email protected]> wrote:
> 
>> This worked for me. When initializing your UIView, add an instance variable 
>> "shapeLayer" and do this,
>> 
>>         shapeLayer = [CAShapeLayer layer];
>>         [[self layer] addSublayer:shapeLayer];
>> 
>> 
>> In drawRect, set up your path and do this,
> 
> There is no need to do this inside of drawRect. In fact by doing so (unless 
> your UIView actually needs to draw something) you've unnecessarily increased 
> your memory footprint and reduce the performance to start the animation.
> 
> If you want the animation to happen as soon as the view is placed in the 
> window, the correct place to do this is inside of -[UIView didMoveToWindow:]. 
> Just check that the moved to window is not nil (or nothing will happen).
> 
>> 
>>     CABasicAnimation *pathAnimation = [CABasicAnimation 
>> animationWithKeyPath:@"strokeEnd"];
>>     pathAnimation.duration = 4.0;
>>     pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
>>     pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
>>     [shapeLayer addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
> 
> You can also do this implicitly once the layer is in a layer tree by setting 
> the animation duration on the current CATransaction and setting the strokeEnd 
> directly.
> 
>> 
>> 
>> 
>> That seems to be all that is needed.
>> 
>> David
>> 
>> 
>> 
>> 
>> On Oct 23, 2012, at 11:37 AM, David Duncan <[email protected]> wrote:
>> 
>>> On Oct 23, 2012, at 4:37 AM, Roland King <[email protected]> wrote:
>>> 
>>>> I want to animate the drawing of  CGPath in a UIView, so it looks as if 
>>>> it's being drawn. I have the UIView, I have the CGPath, I am able to split 
>>>> the CGPath at any point from 0 to 100% into that which should be drawn and 
>>>> that which shouldn't yet, that's all done, so I can, fairly efficiently, 
>>>> call -(CGPath)[ myObject fractionalPath:(CGFloat)fraction ] and get a 
>>>> path. 
>>> 
>>> 
>>> You can do this with a CAShapeLayer by animating the strokeEnd property. 
>>> Should be very simple to do, although if your path is very complex it may 
>>> make more sense to break it into pieces and use multiple shape layers 
>>> animated sequentially.
>>> --
>>> David Duncan
>>> 
>>> 
>>> _______________________________________________
>>> 
>>> Cocoa-dev mailing list ([email protected])
>>> 
>>> Please do not post admin requests or moderator comments to the list.
>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>> 
>>> Help/Unsubscribe/Update your Subscription:
>>> https://lists.apple.com/mailman/options/cocoa-dev/rowlandd%40sbcglobal.net
>>> 
>>> This email sent to [email protected]
>> 
> 
> --
> David Duncan
> 

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to