Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you really should do is to <strong>animate the stroke of a CAShapeLayer</strong> where the path is a circle. This will be accelerated using Core Animation and is less messy then to draw part of a circle in -drawRect:.</p> <p>The code below will create a circle shape layer in the center of the screen and animate the stroke of it clockwise so that it looks as if it is being drawn. You can of course use any shape you'd like. (You can read <a href="http://oleb.net/blog/2010/12/animating-drawing-of-cgpath-with-cashapelayer/" rel="noreferrer" title="Animating the stroke of a shape layer">this article</a> on Ole Begemanns blog to learn more about how to animate the stroke of a shape layer.)</p> <p><strong>Note:</strong> that the stoke properties are not the same as the border properties on the layer. To change the width of the stroke you should use "lineWidth" instead of "borderWitdh" etc.</p> <pre><code>// Set up the shape of the circle int radius = 100; CAShapeLayer *circle = [CAShapeLayer layer]; // Make a circular shape circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius) cornerRadius:radius].CGPath; // Center the shape in self.view circle.position = CGPointMake(CGRectGetMidX(self.view.frame)-radius, CGRectGetMidY(self.view.frame)-radius); // Configure the apperence of the circle circle.fillColor = [UIColor clearColor].CGColor; circle.strokeColor = [UIColor blackColor].CGColor; circle.lineWidth = 5; // Add to parent layer [self.view.layer addSublayer:circle]; // Configure animation CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; drawAnimation.duration = 10.0; // "animate over 10 seconds or so.." drawAnimation.repeatCount = 1.0; // Animate only once.. // Animate from no part of the stroke being drawn to the entire stroke being drawn drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f]; drawAnimation.toValue = [NSNumber numberWithFloat:1.0f]; // Experiment with timing to get the appearence to look the way you want drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; // Add the animation to the circle [circle addAnimation:drawAnimation forKey:@"drawCircleAnimation"]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload