- (void)drawRect:(CGRect)rect {
CGContextRef context=UIGraphicsGetCurrentContext();//获得画图环境
CGContextSetLineWidth(context, 10.0);//线条粗细
CGContextSetStrokeColorWithColor(context, [[UIColor colorWithRed:101.0/255.0 green:144.0/255.0 blue:220.0/255.0 alpha:1.0] CGColor]);//画笔色
CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);//填充色
CGContextAddArc(context, 100, 100, 20, -M_PI/2.0, endAngle*M_PI-M_PI/2.0, 0);//从最上端开始顺时针画圈
CGContextDrawPath(context, kCGPathFillStroke);
}
- (void)viewDidLoad {
[super viewDidLoad];
ball=[[Ball alloc] initWithFrame:CGRectMake(0.0, 0.0, 200, 200)];
[self.view addSubview:ball];
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(timerHandler:) userInfo:nil repeats:YES];
}
-(void)timerHandler:(NSTimer*)timer
{
if (ball.endAngle < 1.9) {
ball.endAngle=ball.endAngle+0.1;
}
[ball setNeedsDisplay];
[ball move];
}