我在 IOS4 mapkit 中有一个可拖动的注释,当注释被拖动到新位置时,我试图调用一个事件。
我的代码目前看起来像:
- (void)mapViewMKMapView *)mapView annotationViewMKAnnotationView *)annotationView
didChangeDragStateMKAnnotationViewDragState)newState fromOldStateMKAnnotationViewDragState)oldState
{
if (newState == MKAnnotationViewDragStateEnding)
{
CLLocationCoordinate2D droppedAt = annotationView.annotation.coordinate;
NSLog(@"dropped at %f,%f", droppedAt.latitude, droppedAt.longitude);
//update the annotation
//see if its an information annotation
if ([annotationView.annotation isKindOfClass:[InfoAnnotation class]]) {
NSLog(@"Info annotation updating..");
InfoAnnotation* userAnnotation = ((InfoAnnotation *)annotationView.annotation);
[userAnnotation updateLocationWithServerForConvoy: self.title];
}
}
}
代码只是简单地记录更新,然后告诉注解将其更新发送到我的服务器,这是一种自定义方法。
此方法似乎被多次触发,请参阅此处的日志:
2011-06-15 01:12:39.347 Convoy[1699:207] dropped at 37.340206,-122.027550
2011-06-15 01:12:39.347 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:39.658 Convoy[1699:207] dropped at 37.340206,-122.027550
2011-06-15 01:12:39.659 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:39.957 Convoy[1699:207] dropped at 37.340206,-122.027550
2011-06-15 01:12:39.958 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:43.415 Convoy[1699:207] dropped at 37.339251,-122.026691
2011-06-15 01:12:43.416 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:43.713 Convoy[1699:207] dropped at 37.339251,-122.026691
2011-06-15 01:12:43.713 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:44.006 Convoy[1699:207] dropped at 37.339251,-122.026691
2011-06-15 01:12:44.006 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:44.297 Convoy[1699:207] dropped at 37.339251,-122.026691
2011-06-15 01:12:44.297 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:54.825 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:54.825 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:55.150 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:55.150 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:55.475 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:55.476 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:55.771 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:55.772 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:56.070 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:56.070 Convoy[1699:207] Info annotation updating..
每次我拖动它时(即在间隙中),它的调用次数似乎都会增加 1。谁能给我任何想法可能导致这种情况?
Best Answer-推荐答案 strong>
如果有人仍然想知道 - 您必须将 MKAnnotationView 拖动状态设置为
MKAnnotationViewDragStateNone .
所以代码是:
- (void)mapViewMKMapView *)mapView annotationViewMKAnnotationView *)annotationView didChangeDragStateMKAnnotationViewDragState)newState fromOldStateMKAnnotationViewDragState)oldState
{
if (newState == MKAnnotationViewDragStateEnding)
{
/* ... */
[annotationView setDragState:MKAnnotationViewDragStateNone];
// If you are animating - move the above into the completion block
}
}
关于objective-c - annotationView didChangeDragState 被多次触发,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/6345888/
|