I would like to constantly update my user interface in accordance with MKMapView when the user zooms or scrolls the map. (Not only after scrolling is over, it works great.)
I tried delegating the mapView: regionWillChangeAnimated: method, which, according to the documentation, "is called whenever the currently displayed map area changes. During scrolling, this method can be called many times to report updates to the map's position." https://developer.apple.com/documentation/mapkit/mkmapviewdelegate
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated { [self updateUIAcordingToMapViewRegionChange]; }
But, unfortunately, this does not work, because the documentation does not seem to be telling the truth. The method is called only once at the very beginning of the change in the region. During scrolling, when the finger is down and moving, the method is no longer called.
The only post I could find about this issue was written by a member of macrumors namanhams: http://forums.macrumors.com/showthread.php?t=1225172 But no one came up with any ideas ...
As a workaround, I tried setting the timer in regionWillChange (and invalidating it in regionDidChange):
- (void)handleRegionChange:(NSTimer*)timer { [self updateUIAcordingToMapViewRegionChange]; } - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated { self.mapRegionIsChangingTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(handleRegionChange:) userInfo:nil repeats:YES]; }
But that doesn't work either. All method calls from the timer are executed immediately after the completion of scrolling. It looks like scrolling mapView is blocking the main thread or something ...
I also read this post about stackoverflow, but unfortunately did not quite understand it: Track MKMapView redraw events. So if the solution to my problem really lies in that SO stream, please let me know about it and I will try to figure it out.
I still hope that I'm just too dumb or too blind to find the right delegate method, and really appreciate any tips, workarounds and best practices to deal with tracking the MKMapView region.