MKMapView regionDidChangeAnimated not always called!
Asked Answered
N

5

12

This is frustrating me!!!

It will be called most of the time but then it stops responding to the pinches. It will be called on a screen rotate and a double tap. Not to a pinch!

Help!

Nub answered 7/11, 2010 at 16:29 Comment(3)
Did ya ever get a solution to this?Kirchner
There is some discussion of this in Apple's forums: devforums.apple.com/message/525411Ethiopian
If you are using a custom annotation view that does its own touch handling, then check out this discussion: iphonedevsdk.com/forum/iphone-sdk-development/…Ethiopian
R
7

I was working on some code that had the same issue and turns out the problem was a subview with a UIGestureRecognizer had been added as a subview to MKMapView, and sometimes, they would cause some delegate methods not to fire.

So make sure you aren't adding subviews or anything to the MKMapView.

Hope this helps.

Rosemaryrosemond answered 12/5, 2011 at 23:0 Comment(0)
N
3

I was moving the map in code and then it appears I needed to call

[mapView setNeedsDisplay];

After!

Nub answered 7/11, 2010 at 18:31 Comment(0)
N
1

I think this problem may have something to do with multi-threading.

I had the same problem this morning. I use a gesture recognizer to capture long press event and then add a pin to the mapview. If works well but after a few rounds, the region did change method stop being called.

I tried a few solutions here but none works. Then I recalled some other issue I had before with multi-threading nature of actions. So I try to moved the code that controls the mapview in long press action to a block that runs in main thread. And the problem is solved.

Nelrsa answered 7/2, 2012 at 1:1 Comment(0)
A
0

I managed to solve this problem by disabling the gesture recognizer within the touchesBeganCallback

self.tapInterceptor.touchesBeganCallback = ^(NSSet *touches, UIEvent *event) {
    self.tapInterceptor.enabled = NO;
    // do something
};

and reenabling it in the regionDidChangeAnimated delegate method

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
    self.tapInterceptor.enabled = YES;
    // do something
}
Abuttals answered 20/7, 2012 at 20:26 Comment(0)
B
0

Whenever a tap gesture recognizer added to the mapview, setting

recognizer.cancelsTouchesInView = NO;

takes care of the problem if your business logic allows for double processing if touches on mapview (by MKMapView AND the gesture recognizer that was most recently interfering with the region[Will,Did]ChangeAnimated:)

Bron answered 1/2, 2018 at 12:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.