pointInView always returns NO
I need to know if a point is inside at lease one of the views in a given set of views. For that, I used UIView's pointInView method, but it always returns NO. As an act of despair, I checked if the view's center point is inside the view and it also returned NO. This is the code I've u开发者_高级运维sed for that:
BOOL wasPointFound = NO;
NSArray *views = [view subviews];
for (UIView *curView in views)
{
if ([curView pointInside:curView.center withEvent:nil])
{
wasPointFound = YES;
break;
}
}
if (!wasPointFound)
NSLog(@"NO");
else
NSLog(@"YES");
Can anybody please tell me what I'm doing wrong?
Thanks,
PointInView is used to check if touch event is inside a view, that means that it is related to the window and not to the view. Taking curView.center is relative to the view therefore there is a good chance that using it will return false. Try using CGPointMake(curView.frame.origin.x+curView.center.x,curView.frame.origin.y+curView.center.y) This should return YES
精彩评论