Question about touches that begin in a UIView's frame and end in its child's.

Discussion in 'iOS Programming' started by moonman239, Feb 21, 2014.

  1. moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #1
    Which of the two views will receive the message that the touches ended?
     
  2. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #2
    I believe you want to read Event Handling Guide for iOS. As seen in the "The Responder Chain Follows a Specific Delivery Path", the response starts at the child view tapped and works it way through the parents until claimed, or not claimed. If claimed by the child, then normally the event stops there, although as seen in the "Important" entry at the bottom of that document, you can forward it.
     
  3. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #3
    Based on behavior in an app I'm developing, I'm guessing that once a user drags a view into another one, the former view becomes a subview of the latter view, and this latter view responds to the touch events.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Don't guess. Confirm.

    Devise a test to validate your presumption. Run the test to see if you are correct or not. Or re-do the test to adjust for something you didn't realize. Rinse and repeat.
     
  5. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #5
    I often do what dejo suggested. I have many little apps where the name begins with the word Sample which makes them easy to find in my dev folder.

    Today I created SampleResponderChain and played around with several possibilities and refreshed my memory. I created a subclass of UIView that implements touchesBegan which NSLogs some information. I also used a generic UIView in my testing. I tested what happens when these views are subviews of a common view, and what happens when one is a subview of another. I also tested what occurs when there is overlapping and a view may not be fully contained within another one.

    These little apps are a great way to focus on a single interest. They can take from a few minutes to an hour or two of time. I always come away with a better understanding of how Cocoa works.
     

Share This Page