views:

149

answers:

2

Hi every one !

I juste watch this effect :

alt text

I would like to reproduce it. Is it simply a CGPath animation? Have you got some indications so implement this beautiful loader view ? Thanks for your tips ;)

+1  A: 

It's not that hard actually.

I don't have time to write the code (although it would be relativly easy), but I'll give you a hint: use a timer and arc.

tadej5553
Yeah I don't want a code just hint I wanna success by myself ;) so AddLineToArc ? But I don't know how to color a CGPath
Pierre
Any idea to help? :)
Pierre
Sorry, I was away for a while.Yes, add arc method would do (just look in the documentation).You don't set a color to the particular path, youjust set the color.Here's an example [[UIColor redColor] set]. You can also choose to set only the fill color (setFill) or the stroke color (setStroke).
tadej5553
Yes ok but I have to implement some CGContext ?
Pierre
You have to make a CGPath and add the arc to it. Then add the path to CGContext, and draw the path with CGContext.
tadej5553
Ok! Thanks !So I made that and it works (http://grab.by/61nH) :- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGMutablePathRef path = CGPathCreateMutable(); CGPathAddArc(path, NULL, 150, 200, 100, 270*(PI/180), 280*(PI/180), false); CGContextSetRGBStrokeColor(context, 1, 0, 0, 1); CGContextSetLineWidth(context, 20); CGContextSetShadowWithColor(context, CGSizeMake(0, 0), 30, [UIColor redColor].CGColor); CGContextAddPath(context, path); CGContextStrokePath(context); }I added a timer and try something but doesn't work for increasing end angle
Pierre
You mean you can't increase the angle of the arc?Post your code, maybe I can help.
tadej5553
I posted my cade as a new answer
Pierre
A: 

I tried this :

- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        self.backgroundColor = [UIColor blackColor];
        context = UIGraphicsGetCurrentContext();
        second = 0;

    }
    return self;
}


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {

    [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(increase) userInfo:nil repeats:NO];

}

-(void)increase
{
    second ++;
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathAddArc(path, NULL, 150, 200, 100, 270*(PI/180), second*(PI/180), false);

    CGContextSetRGBStrokeColor(context, 1, 0, 0, 1);
    CGContextSetLineWidth(context, 20);
    CGContextSetShadowWithColor(context, CGSizeMake(0, 0), 30, [UIColor redColor].CGColor);
    CGContextAddPath(context, path);
    CGContextStrokePath(context);

    [self setNeedsDisplay];
}

But I lost the draw and nothing is happening.

Pierre
Shouldn't the drawing code be in the drawrect?Try moving the draqwing code there and the timer in the init function.
tadej5553
Yes it's almost working but it increase one time and it's done.I have an error from the context (invalid context) because in each call of drawRext I have this line :CGContextRef context = UIGraphicsGetCurrentContext();
Pierre