检测 MKMapView 何时停止移动
Detecting when MKMapView has stopped moving
每当用户移动我的 MKMapView 时,我都会在地图上加载更多图钉。现在,我正在使用这段代码来检测他们何时拖动它:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
- (void)didDragMap:(UIGestureRecognizer*)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateEnded){
CLLocationCoordinate2D topLeft, bottomRight;
topLeft = [self.mapView convertPoint:CGPointMake(0, 0) toCoordinateFromView:self.mapView];
CGPoint pointBottomRight = CGPointMake(self.mapView.frame.size.width, self.mapView.frame.size.height);
bottomRight = [self.mapView convertPoint:pointBottomRight toCoordinateFromView:self.mapView];
[self loadMorePlaces:topLeft bottomRight:bottomRight];
}
}
但是,这只会检测用户何时停止拖动。用户可以 "fling" 地图,地图在他们完成 "dragging" 后仍然可以移动。有什么办法可以找到地图停止移动的时间吗?谢谢
试试这个委托:
每当用户移动我的 MKMapView 时,我都会在地图上加载更多图钉。现在,我正在使用这段代码来检测他们何时拖动它:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
- (void)didDragMap:(UIGestureRecognizer*)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateEnded){
CLLocationCoordinate2D topLeft, bottomRight;
topLeft = [self.mapView convertPoint:CGPointMake(0, 0) toCoordinateFromView:self.mapView];
CGPoint pointBottomRight = CGPointMake(self.mapView.frame.size.width, self.mapView.frame.size.height);
bottomRight = [self.mapView convertPoint:pointBottomRight toCoordinateFromView:self.mapView];
[self loadMorePlaces:topLeft bottomRight:bottomRight];
}
}
但是,这只会检测用户何时停止拖动。用户可以 "fling" 地图,地图在他们完成 "dragging" 后仍然可以移动。有什么办法可以找到地图停止移动的时间吗?谢谢
试试这个委托: