0
所以我想做一些看起来非常简单的事情,但是证明其他方面比较明智,我想在触摸我注册的地方绘制一个方形。我似乎无法让它工作。在touchesBegin我调用一个名为drawSquare的自定义方法,它发送一个CGRect。我知道我一定在做一些简单的错误,但我对Xcode/cocoa-touch中绘制原语不够了解。任何帮助将不胜感激。也是在这里是我的代码:可可触摸 - 用触摸点绘制核心图形
- (void)drawSquare:(CGRect)rect{
//Get the CGContext from this view
CGContextRef context = UIGraphicsGetCurrentContext();
//Draw a rectangle
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
//Define a rectangle
CGContextAddRect(context, rect);
//Draw it
CGContextFillPath(context);
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches) {
// gets the coordinats of the touch with respect to the specified view.
CGPoint touchPoint = [touch locationInView:self];
CGRect rect = CGRectMake(touchPoint.x, touchPoint.y, 50, 50);
[self drawSquare:rect];
}
}
你能解释一下吗? – Joe 2010-09-27 16:32:57