我是一名目标 C 程序员。我正在开发一个通用应用程序。在这个应用程序中,我想使用 Quartz 绘制一个正方形,但不完全在一帧中,而是一帧一帧。在下面的代码中有一种可能性。但它不是很好,因为我想画矩形、圆形和其他东西。那么,有没有更好的方法来绘制这些东西。
-(void)drawRect:(CGRect)rect {
    [self drawARect];
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 20.0);
    CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
    CGFloat components[] = {0.0, 0.0, 1.0, 1.0};
    CGColorRef color = CGColorCreate(colorspace, components);
    CGContextSetStrokeColorWithColor(context, color);
    if (!firstLineReady) {
        CGContextMoveToPoint(context, 200, 200);
        CGContextAddLineToPoint(context, x, y);
    }
    if (firstLineReady && !secondLineReady) {
        CGContextMoveToPoint(context, 200, 200);
        CGContextAddLineToPoint(context, 600, 200);
        CGContextMoveToPoint(context, 600, 200);
        CGContextAddLineToPoint(context, x, y);
    }
    if (secondLineReady && !thirdLineReady) {
        CGContextMoveToPoint(context, 200, 200);
        CGContextAddLineToPoint(context, 600, 200);
        CGContextMoveToPoint(context, 600, 200);
        CGContextAddLineToPoint(context, 600, 600);
        CGContextMoveToPoint(context, 600, 600);
        CGContextAddLineToPoint(context, x, y);
    }
    if (thirdLineReady && ! fourthLineReady) {
        CGContextMoveToPoint(context, 200, 200);
        CGContextAddLineToPoint(context, 600, 200);
        CGContextMoveToPoint(context, 600, 200);
        CGContextAddLineToPoint(context, 600, 600);
        CGContextMoveToPoint(context, 600, 600);
        CGContextAddLineToPoint(context, 200, 600);
        CGContextMoveToPoint(context, 200, 600);
        CGContextAddLineToPoint(context, x, y);
    }
    if (fourthLineReady) {
        CGContextMoveToPoint(context, 200, 200);
        CGContextAddLineToPoint(context, 600, 200);
        CGContextMoveToPoint(context, 600, 200);
        CGContextAddLineToPoint(context, 600, 600);
        CGContextMoveToPoint(context, 600, 600);
        CGContextAddLineToPoint(context, 200, 600);
        CGContextMoveToPoint(context, 200, 600);
        CGContextAddLineToPoint(context, 200, 200);
        [timer invalidate];        
    }
    CGContextStrokePath(context);
    CGColorSpaceRelease(colorspace);
    CGColorRelease(color);
}
- (void) drawARect{
    if (!firstLineReady) {
        x+=speed; y+=0;
        if (x>=600) {
            x=600;
            firstLineReady = YES;
        }
    }
    if (firstLineReady && !secondLineReady ) {
        x+=0; y+=speed;
        if (y>=600) {
            y=600;
            secondLineReady = YES;
        }
    }
    if (firstLineReady && secondLineReady && !thirdLineReady  ) {
        x-=speed; y+=0;
        if (x<=200) {
            x=200;
            thirdLineReady = YES;
        }
    }
    if (firstLineReady && secondLineReady && thirdLineReady ) {
        x+=0; y-=speed;
        if (y<=200) {
            y=200;
            fourthLineReady = YES;
        }
    }
}
是否可以提供CGContextAddLineToPoint像铅笔或圆珠笔这样的自定义图案?