objective-c - annotationView didChangeDragState 被多次触发
<p><p>我在 IOS4 mapkit 中有一个可拖动的注释,当注释被拖动到新位置时,我试图调用一个事件。</p>
<p>我的代码目前看起来像:</p>
<pre><code> - (void)mapView:(MKMapView *)mapViewannotationView:(MKAnnotationView *)annotationView
didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)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 (]) {
NSLog(@"Info annotation updating..");
InfoAnnotation* userAnnotation = ((InfoAnnotation *)annotationView.annotation);
;
}
}
}
</code></pre>
<p>代码只是简单地记录更新,然后告诉注解将其更新发送到我的服务器,这是一种自定义方法。</p>
<p>此方法似乎被多次触发,请参阅此处的日志:</p>
<pre><code>2011-06-15 01:12:39.347 Convoy dropped at 37.340206,-122.027550
2011-06-15 01:12:39.347 Convoy Info annotation updating..
2011-06-15 01:12:39.658 Convoy dropped at 37.340206,-122.027550
2011-06-15 01:12:39.659 Convoy Info annotation updating..
2011-06-15 01:12:39.957 Convoy dropped at 37.340206,-122.027550
2011-06-15 01:12:39.958 Convoy Info annotation updating..
2011-06-15 01:12:43.415 Convoy dropped at 37.339251,-122.026691
2011-06-15 01:12:43.416 Convoy Info annotation updating..
2011-06-15 01:12:43.713 Convoy dropped at 37.339251,-122.026691
2011-06-15 01:12:43.713 Convoy Info annotation updating..
2011-06-15 01:12:44.006 Convoy dropped at 37.339251,-122.026691
2011-06-15 01:12:44.006 Convoy Info annotation updating..
2011-06-15 01:12:44.297 Convoy dropped at 37.339251,-122.026691
2011-06-15 01:12:44.297 Convoy Info annotation updating..
2011-06-15 01:12:54.825 Convoy dropped at 37.337135,-122.025833
2011-06-15 01:12:54.825 Convoy Info annotation updating..
2011-06-15 01:12:55.150 Convoy dropped at 37.337135,-122.025833
2011-06-15 01:12:55.150 Convoy Info annotation updating..
2011-06-15 01:12:55.475 Convoy dropped at 37.337135,-122.025833
2011-06-15 01:12:55.476 Convoy Info annotation updating..
2011-06-15 01:12:55.771 Convoy dropped at 37.337135,-122.025833
2011-06-15 01:12:55.772 Convoy Info annotation updating..
2011-06-15 01:12:56.070 Convoy dropped at 37.337135,-122.025833
2011-06-15 01:12:56.070 Convoy Info annotation updating..
</code></pre>
<p>每次我拖动它时(即在间隙中),它的调用次数似乎都会增加 1。谁能给我任何想法可能导致这种情况? </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>如果有人仍然想知道 - 您必须将 MKAnnotationView 拖动状态设置为
<code>MKAnnotationViewDragStateNone</code>.</p>
<p>所以代码是:</p>
<pre><code>- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState
{
if (newState == MKAnnotationViewDragStateEnding)
{
/* ... */
;
// If you are animating - move the above into the completion block
}
}
</code></pre></p>
<p style="font-size: 20px;">关于objective-c - annotationView didChangeDragState 被多次触发,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/6345888/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/6345888/
</a>
</p>
页:
[1]