tags:

views:

15

answers:

1

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 used 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,

+1  A: 

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

Guy Ephraim
You're right! Other than the fact that it should be:CGPointMake(views.frame.origin.x+curView.center.x,views.frame.origin.y+curView.center.y).Thanks!
Chonch