Haris Hussain
Haris Hussain

Reputation: 2581

Tapping on Buttons over MapView is zooming the Map..?

I have a MapView, Over which i have added a UIView (0, 216, 320, 200) contain 10 UIButtons. This UIView is to work like a menu, and Shows and Hides on a certain button action.

The problem here is, While the Menu is showing, when i tap a button single ime, it works perfectly, but tapping it very quickly multiple times makes the MapView Zoom(Which is under the UIView which contain the button). It means the touch event is passing to MapView.

Detail: Tapping on the button very quickly cause in MapView Zoom, and the Button Action performs when you stop tapping.

How can i prevent that?

Upvotes: 0

Views: 360

Answers (2)

Haris Hussain
Haris Hussain

Reputation: 2581

Yes, so the problem was, I was adding UIView as subview over MapView.. I fixed it by adding the UIView as subview on self.view

Upvotes: 0

brindy
brindy

Reputation: 4695

What you could do is disable user interaction for the duration of your button's handler. So in the selector do:

-(void)buttonSelector:(id)sender {
    _mapView.userInteractionEnabled = NO;

    // ... do what your button needs to do

    _mapView.view.userInteractionEnabled = YES;
}

Of course, this assumes your button gets the event before the map view... which I think it should because it's on top of the map view.

To handle the rapid tapping, you could create a subclass of UIButton and use the following code:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    _mapView.userInteractionEnabled = NO;
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{
    _mapView.userInteractionEnabled = YES;
}

In the builder change the class of the UIButton to your subclass. If you debug the touch in the set passed to the touchesEnd method and look at the tapCount, you'll see all your taps have been caught here.

Upvotes: 1

Related Questions