0

I'm trying to get a particular event to work. The user should touch one button (A), this button would pop-up some UIView, in which there is another button (B).

If the user touchUpInside button A, the popup should disappear, and the Button (B) would not be clickable. However, if the user clicks on button (A), and then drag his finger into the button (B) then this button (B) will be selected, but only fire if the user TouchUpInside this button (B)

I have tried the most obvious TouchDragEnter and TouchDragInside, but it does not do what I expected, you have to touchDownInside first for it to work. Since the TouchDownInside event has been done on the button (A), it can't be done on the button (B)

Have I missed something, or should I just go ahead a create a subClass of my own for this particular behaviour ?

To add some difficulty, the button (A) and button (B) are not on the same UIView.

TheSquad
  • 7,385
  • 8
  • 40
  • 79

2 Answers2

0

If I was to go about this, I would ignore touchUpInside etc altogether and just focus on the drag event. In the touchesMoved method, keep checking where the touches are, and if they intersect the rect of the view you are concerned about.

Something like this : (apologies for incomplete example)

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint currentPoint = [touch locationInView:self];
    if ( CGRectContainsPoint(imageView.bounds, locationInView) ) {
    // Point lies inside the bounds...
Luke Smith
  • 1,218
  • 12
  • 17
  • Of course I tried that... only the users should touch the button A first (which is on view X) then be able to drag to Button B (which is on View Y)... Since the Touch event occured on button A (View X) any other touch event would not be called from another view. – TheSquad Oct 05 '15 at 13:47
  • You would have to control all this stuff from the superview of both buttons. I doubt you can do it from one view while moving outside of its bounds into another. – Luke Smith Oct 05 '15 at 13:52
0

I have just created a library called PopMenu that implements exactly the function you mentioned. The idea is it pops out buttons when you touchdown on the menu button and keep tracking the user's finger until the user touches up on the screen. It returns the button that the user ended his touch on.

enter image description here

Khaled Zayed
  • 306
  • 2
  • 6