问题
I'm trying to capture panning and the 'end of scrolling' on an MKMapView. Panning is easy to do with a gesture recognizer. However, MKMapView doesn't seem to implement a UIScrollViewDelegate in iOS 6. That makes the solution in Is there way to limit MKMapView maximum zoom level? not work.
Thoughts? Ideally I would have just leveraged the UIScrollViewDelegate as such:
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if ([super respondsToSelector:@selector(scrollViewDidEndDecelerating:)]) {
[super scrollViewDidEndDecelerating:scrollView];
}
[self.myDelegate mapDidFinishPanning:self];
}
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate: (BOOL)decelerate {
if ([super respondsToSelector:@selector(scrollViewDidEndDragging:)]) {
[super scrollViewDidEndDragging:scrollView];
}
if(!decelerate) {
[self.myDelegate mapDidFinishPanning:self];
}
}
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
if ([super respondsToSelector:@selector(scrollViewWillBeginDragging:)]) {
[super scrollViewWillBeginDragging:scrollView];
}
[self.myDelegate mapDidBeginPanning:self];
}
inside a class extending MKMapView
@interface MyMapView : MKMapView <UIScrollViewDelegate, UIGestureRecognizerDelegate>
but that won't work in iOS 6. I can't see anything sufficient in MKMapViewDelegate.
回答1:
Answering myself. I implemented all of MKMapViewDelegate's methods and it seems that
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
is called on pan, and
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
is called as soon as deceleration stops (and not before).
来源:https://stackoverflow.com/questions/14108801/detecting-panning-decelerate-of-mkmapview