我正在尝试捕捉MKMapView上的平移和“滚动结束”。使用手势识别器可以轻松进行平移。但是,MKMapView似乎没有在iOS 6中实现UIScrollViewDelegate。这使得Is there way to limit MKMapView maximum zoom level?中的解决方案无效。
思考?理想情况下,我只会利用UIScrollViewDelegate:
-(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];
}
扩展MKMapView
的类@interface MyMapView : MKMapView <UIScrollViewDelegate, UIGestureRecognizerDelegate>
但这在iOS 6中不起作用。我在MKMapViewDelegate中看不到任何足够的内容。
答案 0 :(得分:9)
回答自己。我实现了所有MKMapViewDelegate的方法,似乎
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
在pan上调用,
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
一旦减速停止(而不是之前),就会调用。