0
我在繪製觸摸手勢上的矩形或三角形時遇到問題。這裏是代碼:在iPhone上繪製圖形
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self];
// move the cannon to the touched location
x = location.x;
[self moveCannon];
[self setNeedsDisplay];
}
-(void) moveCannon
{
// draw the cannot as a triangle for right now
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 20.0f, 100.0f);
CGPathAddLineToPoint(path, NULL, 50.0f, 100.0f);
CGPathAddLineToPoint(path, NULL, 50.0f, 20.0f);
CGPathAddLineToPoint(path, NULL, 50.0f, 100.0f);
CGPathCloseSubpath(path);
CGContextSetFillColorWithColor(self.context, [UIColor redColor].CGColor);
CGContextAddPath(self.context, path);
CGContextFillPath(self.context);
}
我錯過了什麼?
發現問題是因爲我沒有正確調用我的自定義方法。 – azamsharp 2010-07-06 12:24:08