Note that there are some explanatory texts on larger screens.

plurals
  1. POiPhone: Drawing a curved line until it becomes a circle animation
    primarykey
    data
    text
    <p>I wish to draw a curved line until it makes a full rotation and joins to become a complete circle, just the circle outline, not filled. This has to be animated over a number of seconds.</p> <p>Can anyone point me in the right direction? I already asked a <a href="https://stackoverflow.com/questions/7991086/iphone-core-animation-drawing-a-circle">similar question</a> to this but I worded it incorrectly so everyone had a hard time understanding what I meant and thus it got lost in the sea of questions.</p> <p>Many Thanks for any help</p> <p>[edit] </p> <p>I'm currently sub-classing UIView and overriding drawRect. I found code to draw a filled circle but I only require the stroke.</p> <pre><code>- (void)drawRect:(CGRect)rect { // Drawing code CGRect allRect = self.bounds; CGRect circleRect = CGRectInset(allRect, 2.0f, 2.0f); CGContextRef context = UIGraphicsGetCurrentContext(); // Draw background CGContextSetRGBStrokeColor(context, self.strokeValueRed, self.strokeValueGreen, self.strokeValueBlue, self.strokeValueAlpha); // white CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 0.1f); // translucent white CGContextSetLineWidth(context, self.lineWidth); CGContextFillEllipseInRect(context, circleRect); CGContextStrokeEllipseInRect(context, circleRect); // Draw progress CGPoint center = CGPointMake(allRect.size.width / 2, allRect.size.height / 2); CGFloat radius = (allRect.size.width - 4) / 2; CGFloat startAngle = - ((float)M_PI / 2); // 90 degrees CGFloat endAngle = (self.progress * 2 * (float)M_PI) + startAngle; CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 1.0f); // white CGContextMoveToPoint(context, center.x, center.y); CGContextAddArc(context, center.x, center.y, radius, startAngle, endAngle, 0); CGContextClosePath(context); CGContextFillPath(context); } </code></pre> <p>[edit #2]</p> <p>I changed the code to remove all the fill references but now its not drawing anything :( any ideas?</p> <pre><code>- (void)drawRect:(CGRect)rect { // Drawing code CGRect allRect = self.bounds; CGContextRef context = UIGraphicsGetCurrentContext(); // Draw background CGContextSetRGBStrokeColor(context, self.strokeValueRed, self.strokeValueGreen, self.strokeValueBlue, self.strokeValueAlpha); // white CGContextSetLineWidth(context, 5); // Draw progress CGPoint center = CGPointMake(allRect.size.width / 2, allRect.size.height / 2); CGFloat radius = (allRect.size.width - 4) / 2; CGFloat startAngle = - ((float)M_PI / 2); // 90 degrees CGFloat endAngle = (self.progress * 2 * (float)M_PI) + startAngle; CGContextAddArc(context, center.x, center.y, radius, startAngle, endAngle, 0); CGContextStrokePath(context); } </code></pre> <p>[edit #3] Solution</p> <p>Right I feel like a right dickhead! the problem was that the stroke colour values were not initialised meaning that line was being draw but obviously could not see it!! </p>
    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.
 

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