私は Objective C プログラマーです。私はユニバーサルアプリを開発しています。このアプリでは、Quartz を使用して正方形を描画しますが、完全に 1 つのフレームではなく、フレームごとに描画します。以下のコードには可能性があります。しかし、四角形、円などを描きたいので、あまり良くありません。それで、そのようなものを描くためのより良い方法はありますか.
-(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
鉛筆やバイロのようなカスタム パターンを指定することはできますか?