Detecting if a subview is touched

Discussion in 'iOS Programming' started by drf1229, Jan 23, 2010.

  1. drf1229 macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
    #1
    I'm trying to detect if a UIView inside of another view is touched. I have something like this:
    Code:
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch=[touches anyObject];
    if([touch view]==myview]){
    //Do this code... 
    
    
    }
    
    }
    But it never detects it. Do I need to do something else? I could call touchesMoved within the subview, but then I can't detect if the touch moves outside the view. Any suggestions? Any advice is greatly appreciated!
     
  2. drf1229 thread starter macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
    #2
    Oh wow. I just figured out that when I call touchesMoved in the subview, I could use superview to access a method in the superview, which could then do the action I want. Wish i'd figured it out earlier! Thanks anyway
     
  3. drf1229 thread starter macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
    #3
    Out of curiousity is there a way to solve this problem without doing this?
     

Share This Page