检测平移+减速MKMapView [英] Detecting panning + decelerate of MKMapView
问题描述
我正在尝试捕获MKMapView上的平移和滚动结束".使用手势识别器可以轻松进行平移.但是,MKMapView似乎没有在iOS 6中实现UIScrollViewDelegate.这使得
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.
有什么想法吗?理想情况下,我将像这样利用UIScrollViewDelegate:
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];
}
在扩展MKMapView的类中
inside a class extending MKMapView
@interface MyMapView : MKMapView <UIScrollViewDelegate, UIGestureRecognizerDelegate>
但是在iOS 6中不起作用.我在MKMapViewDelegate中看不到足够的东西.
but that won't work in iOS 6. I can't see anything sufficient in MKMapViewDelegate.
推荐答案
正在回答自己.我实现了MKMapViewDelegate的所有方法,看来
Answering myself. I implemented all of MKMapViewDelegate's methods and it seems that
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
被平移调用,并且
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
减速停止后立即调用
.
is called as soon as deceleration stops (and not before).
这篇关于检测平移+减速MKMapView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!