Search code examples
iphoneiosipadcocoa-touchrubymotion

How to find an UIView by a coordinate/location (x,y)


I have a pan gesture which returns the current location (in x and y coordinates) of the user.

I also have different sized circles which are stacked up on each other.

My question now is, is it possible to find one of those circles (each one is an UIView) by a x,y coordinate? Or how does one find out which UIView's are at the users current location?


Solution

  • Brute Force:

    NSArray *allCircle /*collection of UIviews */
    
    for(UIView *circle in allCircles){
      if(CGRectContainsPoint([circle frame], point))
      {
       // got it !!
        break;
      }
    }