Returning Views Beneath A Touch?

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

  1. HarryWorksInc macrumors regular

    Joined:
    Feb 21, 2010
    #1
    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

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    You could do something like
    Code:
    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

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    Are these subviews not responders?
     
  4. kayloh20 macrumors regular

    Joined:
    Apr 8, 2010
    Location:
    Chicago, IL
    #4
    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