Iphone 触摸位置、框架。CGRectContainsPoint未返回true
我有多个UIImageView子类:Iphone 触摸位置、框架。CGRectContainsPoint未返回true,iphone,ios,uiimageview,uitouch,cgrect,Iphone,Ios,Uiimageview,Uitouch,Cgrect,我有多个UIImageView子类: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { for (UITouch *touch in touches) { CGPoint _location = [touch locationInView:touch.view]; [self processTouch:_location]; } } -(void)p
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches) {
CGPoint _location = [touch locationInView:touch.view];
[self processTouch:_location];
}
}
-(void)processTouch:(CGPoint)location {
DLog(@"location: %f .. bounds: %f : %f" ,location.x, [twoThirdOfTheWayCoordinateX floatValue], [oneThirdOfTheWayCoordinateX floatValue]);
if(CGRectContainsPoint(self.frame, location)) {
DLog(@"1");
if(location.x > [twoThirdOfTheWayCoordinateX floatValue]){
[self oneStar];
} else if (location.x < [oneThirdOfTheWayCoordinateX floatValue]) {
[self zeroStars];
} else if( [twoThirdOfTheWayCoordinateX floatValue] >= location.x && location.x >= [oneThirdOfTheWayCoordinateX floatValue]){
[self halfStars];
}
}
}
从未接到过电话
为什么会这样?第一个DLog被调用
用于初始化实例的代码:
self.instance = [[Class alloc] initWithFrame:CGRectMake(10, 10, 50 , 50)];
self.instance.userInteractionEnabled = YES;
self.instance.image = [UIImage imageNamed:@"0-0.png"];
[self.view addSubview: self.instance];
[self.instance setNeedsDisplay];
将self.frame替换为self.bounds修复了该问题 在freenode上发布iphonedev,这是对8月份的致敬
self.instance = [[Class alloc] initWithFrame:CGRectMake(10, 10, 50 , 50)];
self.instance.userInteractionEnabled = YES;
self.instance.image = [UIImage imageNamed:@"0-0.png"];
[self.view addSubview: self.instance];
[self.instance setNeedsDisplay];