Sita Dulip
Sita Dulip

Reputation: 21

How Can You Stop iOS PinchGesture from Selecting Buttons?

I'm currently writing an iOS application for the iPhone with one particular feature that creates a flowchart on the fly. The flowchart that is created is one enormous, scrollable view. Each information node of the flowchart contains buttons that automatically moves the view to the next information node. At any point in time, a user can use a pinch gesture to zoom out of the current information node and see the flowchart in its entirety.

My problem is this: I notice that if a user begins this pinch motion with one of their fingers tapping one of the buttons in an information node then this gesture takes precedence and the next node is shown as opposed the pinch gesture zooming out from the current node.

I've been looking on StackOverflow and have tried several things to fix this, but nothing yet has seemed to work. I was wondering if anyone has had similar issues and if they were able to overcome the issue?

Upvotes: 1

Views: 188

Answers (1)

Sita Dulip
Sita Dulip

Reputation: 21

Using @Till's advice and looking into my issue a bit more, I've done something that's worked for me and I thought I would share it here in case anyone else had similar issues or desires.

I was able to create UIViews that I could use to act as semi-buttons. For each of these views, I greated UITapGestureRecognizers and targeted them towards methods that would check to see if the sender's state is StateEnded:

-(void)handleButtonTap:(UITapGestureRecognizer *)sender
{
  if(sender.state == UIGestureRecognizerStateEnded)
    // Go on and do the code here
}

However, wanting to still maintain the look of the original iOS Buttons I did one step further. For each UIButton that I created, I did not associate a target with these buttons and instead created UIViews for each button. These UIViews were completely blank with a background color of "Clear." In this manner, I can now have my buttons, but still get the functionality I desired.

I hope this helps anyone else with similar issues. Thanks again to @Till for the advice.

Upvotes: 1

Related Questions