Detecting panning + decelerate of MKMapView

狂风中的少年 提交于 2020-01-02 06:16:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!