views:

150

answers:

1

Greets. A somehow detailed explanation on my problem, and what I have already done, and what I cannot do.

I want to create a behavior resembling the one in the iPhone's keyboard. Basically, I want a view to appear when the user taps a button and WHILE the user taps that button.

This, I accomplished.

When the user lets go of the button WHILE his finger is on that button's area, I want to trigger an action "doing stuff".

This, I was also able to do.

Since all the buttons are near (like in the keyboard) and I don't want the user to select other button than the one he pressed, I reduced the hit area for the button using the -(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent )event function.

When the user presses the button, not lifting its finger, and dragging outside the button area, I want another action to trigger. This is the first problem... This function only triggers when the user's finger is far from the buttons' area, and this time the pointInside function is not being my friend. How can I detect the user finger "left" the button area the moment it exits its bounds?

This, in case you didn't realize... was problem 1.

The second problem is related with the drag enter. Again, I need to limit the area like in the drag exit. But I suppose that when I solve one of these, the other is the same. The problem is that in order to have a behavior like in the keyboard, I may need to detect the user started the touch in another button, never lifted his finger, and changed to another button. I can detect drag enter and drag exit IN THIS ORDER while on the same button. I cannot detect drag enter when the user first touched anywhere else other than the button where I want to detect the drag enter event. Basically what I need is to detect touch on any button (and not anywhere else in the view), and while the user is changing buttons without lifting the finger, I want to detect the new button being touched.

This gigantic paragraph was problem #2.

Any help, as you might guess, is highly appreciated.

Best Regards. Thanks a lot!

+2  A: 

Solved.

I used a custom UIButton class. Then, in

  • (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

  • (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

  • (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

I test if the touch occurred in that custom UIButton. And if it did, I act accordingly.

camilo
Can you explain how you did that? I have the same problem.
XenElement
I changed company. I now work in a different technology. I don't have the code. Sorry my friend, can't help you much further. But as I remember, a touch has a position, and all views have a position... you have to check if the touching position is inside the button view. Hope it helped.
camilo