How do I designate a UIView as a responder for certain touch events?

Discussion in 'iOS Programming' started by moonman239, Mar 24, 2014.

  1. moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #1
    In another app I'm working on, there is a view controller. Within this view controller, there is a UIView. Within this UIView, there are multiple UIViews. I'll call them Amy, Bob, Carol, and Dan. I want Amy to do something when either Bob, Carol, or Dan gets dropped into her. However, I don't want Amy to respond to touchesBegan or touchesMoved, even if the touch begins inside Amy.

    Each instance of Amy's class's parent, by default, responds to all touch events if the touch, or touches, start(s) inside it.
     
  2. JohnsonK macrumors regular

    Joined:
    Mar 6, 2014
    #2
    Well, if you call your UIView something, you are going to have control over it. A simple if statement is enough to stop it from moving
     
  3. iMacFarlane macrumors 65816

    iMacFarlane

    Joined:
    Apr 5, 2012
    Location:
    Adrift in a sea of possibilities
    #3
    Have you tried to disable touch for Amy?

    Code:
    [amy setUserInteractionEnabled:NO];
    
     
  4. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #4
    I don't think that helped.

    I wish I could just nullify the touchesBegan and touchesMoved methods present in the superclass's implementation so either iOS or the compiler treats them like they're not there.

    Edit: Whether or not Amy's userInteractionEnabled property is set to NO, the app does not let the user move Amy.
     
  5. iMacFarlane macrumors 65816

    iMacFarlane

    Joined:
    Apr 5, 2012
    Location:
    Adrift in a sea of possibilities
    #5
    In your original question, you never said you wanted the user to move Amy. You said you didn't want Amy to respond to touch events. You said you wanted Amy to perform an action when other views were dropped within her bounding rectangle.

    Now you want Amy to move? I guess I don't really understand what you're looking to accomplish.
     
  6. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #6
    OK, let me rephrase my original statement.

    Amy, Bob, Carol, and Dan are all UIViews located within a UIViewController. I want the user to be able to move Bob, Carol, and Dan, but not Amy, whose position inside the view controller is supposed to be static.

    My UIViewController has touchesBegan and touchesMoved methods that take care of the dragging part. I wanted Amy to do something when either Bob, Carol, or Dan was dragged inside her boundaries, because I believe it would be best to have the controller do as little as possible.

    Anyways, I created a subclass of UIView and made the main view an instance of that subclass. I will redisable user interaction in my collection view. That way, the UIView will respond anytime a touch ends and pass all other events up the responder chain.
     
  7. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #7
    I just restructured my app so that Bob, Carol, and Dan respond every time a touch begins, moves, and ends. When the touch ends, they will send a message to their delegate.
     

Share This Page