views:

98

answers:

1

I wanted to allow for a method to get called, if a finger was dragged from outside into the bounds of a control. I thought UIControlEventTouchDragEnter would do it, but it doesn't seem to. Does anyone know if there is a way to trigger an action based on a tap sliding into a control?

This is what I was trying, but got no calls to my -fingerSlidIn:

[aButton addTarget:self action:@selector(fingerSlidIn:withEvent: ) forControlEvents: UIControlEventTouchDragEnter];

Thanks!

A: 

This is by design. All events belonging to a continuous touch (from touch down until touch up) go to the view that received the first touch down event. So you will never receive a UIControlEventTouchDragEnter unless the user moved the finger away from the control and back.

To do what you want, you would have to capture the touches on the control's container view and determine manually when the touch coordinates enter your control's frame rect (possibly by calling pointInside:withEvent: for every touch you receive).

Ole Begemann
Sounds right. I have to decide if I want to subclass my container view, or put a large control below the other buttons in order to be the container control.
mahboudz
It's too bad I can't just -addTarget my existing container UIView...
mahboudz
Subclassing the view took all of 5 minutes with barely any additional code. Thanks!
mahboudz
One slight issue: If the touch originates in the control, then the container never gets the touch message and when the touch gets dragged off of that initial control, and slides over to another, touchesMoved never gets to handle the move. I tried making my controls not have any targets, but they still don't pass the touch on to the container view. Disabling the controls doesn't help either. Any thoughts?
mahboudz
Got it. Subclassed my controls too. Simply had their touch messages go to self.nextResponder.
mahboudz
Glad you got it working.
Ole Begemann