拖动注释时callback
我可以拖动我的注释,当我放下它时,我可以读取这个位置。 但是,我需要不断更新我的头衔,我拖动的位置。 我试着添加一个UIPanGestureRecognizer,但是当我拖动注解时不起作用。 拖动注释时,我应该使用什么方法不断调用我的代码?
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState { CLLocationCoordinate2D annoCoord = view.annotation.coordinate; switch (newState) { case MKAnnotationViewDragStateStarting: NSLog(@"Start dragging annotation"); break; case MKAnnotationViewDragStateDragging: NSLog(@"Dragging annotation"); break; case MKAnnotationViewDragStateEnding: [view setDragState:MKAnnotationViewDragStateNone]; // must be here! else multiple calls NSLog(@"Ending dragging annotation at %f : %f", annoCoord.latitude, annoCoord.longitude); break; case MKAnnotationViewDragStateCanceling: NSLog(@"Cancel dragging annotation"); break; case MKAnnotationViewDragStateNone: NSLog(@"None dragging annotation"); break; default: break; } }
当一个状态开始时,我只能得到callback,而不是在拖动过程中。
任何帮助将非常感激。
欢呼声,tord
您可以在MKAnnotationView中心属性上设置观察者。 然后在观察者的callback中,可以将注记视图中心位置从屏幕坐标转换为地理坐标。
[myAnnotationView addObserver:myMapViewDelegate forKeyPath:@"center" options:NSKeyValueObservingOptionNew context:nil]; ... - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { CGPoint position = myAnnotationView.center; //... here take myAnnotationView.centerOffset into consideration to get the correct coordinate CLLocationCoordinate2D newCoordinate = [self.mapView convertPoint:position toCoordinateFromView:self.superview]; }
- 通过手势交换单元格的位置
- IOS:从一个滚动视图拖放imageview到一个视图
- ipad:从一个UITableViewController中拖出一个UITableViewCell,并将其放入另一个UITableViewController中
- iOS >>拖动视图跳回原始位置>>自动布局与UIPanGestureRecognizer问题结合
- IOS 5.1拖放
- iOS 11 dropInteraction执行文件的Drop
- 拖动+旋转使用UIPanGestureRecognizer触摸下车轨道
- iPhone / iOS的:如何实现拖放滚动视图的子视图?
- iOS – UIPanGestureRecognizer:在animation中拖动