有没有办法确定MKMapView
拖动和缩放是否会停止?
现在我添加了UIPanGestureRecognizer
用于拖动MKMapView
,但即使地图正在滚动,当用户抬起手指时我也会立即收到gestureRecognizer.state == UIGestureRecognizerStateEnded
。我想弄清楚的是,当地图仍在移动和/或用户再次触摸地图以再次拖动地图时,如何防止为我的地图注释加载服务器数据?只有在地图停止移动和缩放并且静止一段预定时间时才应调用数据加载机制。
这是我到目前为止所实现的:
- (void)viewDidLoad {
...
UIPanGestureRecognizer* panRec = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(didDragMap:)];
[panRec setDelegate:self];
[panRec setDelaysTouchesBegan:YES];
[panRec setDelaysTouchesEnded:YES];
[panRec setCancelsTouchesInView:YES];
[self.mapView addGestureRecognizer:panRec];
}
选择器方法 didDragMap:
- (void)didDragMap:(UIGestureRecognizer*)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
_searchBar.text = @"";
_filtered = NO;
_crosshair.hidden = NO;
[self removeAllAnnotationExceptOfOriginalLocation];
}
else if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
[self performSelector:@selector(delayAddressResolving:) withObject:nil afterDelay:1.0];
}
}
选择器方法 delayAddressResolving:正在从服务器加载所需数据以显示我的注释信息。
欢迎所有笔记!
答案 0 :(得分:0)
使用以下MKMapViewDelegate
方法:
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
每当地图区域发生变化时,都会调用这些方法。
答案 1 :(得分:0)