Returning Views Beneath A Touch?

Discussion in 'iOS Programming' started by HarryWorksInc, Mar 20, 2012.

  1. HarryWorksInc macrumors regular

    Feb 21, 2010
    Hey, is there a way to have the views beneath a CGPoint returned? I have a script that is creating objects programmatically that aren't defined in the .h file and these views are added as subviews to the current view. I need to be able to interact with them at a later point. The only reason I don't define them in the .h is that I am expecting many of these views (Images) to be created. So can I interact with a view I created in an individual void?
  2. jnoxx macrumors 65816


    Dec 29, 2010
    Aartselaar // Antwerp // Belgium
    You could do something like
    for (UIView *view in someView) {
       if ([view isKindofClass:[UIImageView class]]) {
          //got the view pointer, do something with it.
         //In your script you can assign a TAG value, which u can use to retrieve the view
         if (view.tag == 23) {
             //Hooray, got it, do something awesome with it
    I typed this out of my head, so you need to check some brackets/capitalisation etc.
  3. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    Are these subviews not responders?
  4. kayloh20 macrumors regular

    Apr 8, 2010
    Chicago, IL
    If you call hitTest:withEvent: on the superview of said subviews and pass in a CGPoint (event is optional), it will return the frontmost UIView at that CGPoint.

Share This Page