Я рисую заполненную форму, используя UIBezierPath, и я хочу проверить, касается ли пользователь этой формы.Вот мой код:
- (void)drawRect:(CGRect)rect
{
aShape = [UIBezierPath bezierPathWithOvalInRect:
CGRectMake(0, 0, 200, 100)];
[[UIColor blackColor] setStroke];
[[UIColor redColor] setFill];
CGContextRef aRef = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(aRef, 50, 50);
aShape.lineWidth = 5;
[aShape fill];
[aShape stroke];
CGPoint x = CGPointMake(30, 40);
if([aShape containsPoint:x]) {
NSLog(@"in");
} else {
NSLog(@"out");
}
}
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
}
return self;
}
- (void)dealloc {
[aShape dealloc];
[super dealloc];
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *t = [[touches allObjects] objectAtIndex:0];
CGPoint p = [t locationInView:self];
[aShape containsPoint:p];
}
@end
У меня есть некоторые проблемы с методом: includesPoint.Он работает в drawRect-Code, но не в методе touchesBegan, и я не знаю почему :( Буду признателен за некоторую помощь ... Спасибо.