2016-03-01 84 views

回答

4

要使注释可拖动,请将注释视图的可拖动属性设置为YES。

这通常在viewForAnnotation委托方法中完成。

例如:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
{ 
    if ([annotation isKindOfClass:[MKUserLocation class]]) 
     return nil; 

    static NSString *reuseId = @"pin"; 
    MKPinAnnotationView *pav = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseId]; 
    if (pav == nil) 
    { 
     pav = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId]; 
     pav.draggable = YES; 
     pav.canShowCallout = YES; 
    } 
    else 
    { 
     pav.annotation = annotation; 
    } 

    return pav; 
} 

如果您需要在用户停止拖动和下降的注释, 见来处理:how to manage drag and drop for MKAnnotationView on IOS?

如何管理拖放进行MKAnnotationView的IOS?

另外,你的注解对象(实现MKAnnotation的那个)应该有一个可设置的坐标属性。您正在使用实现setCoordinate的MKPointAnnotation类,以便该部分已经被处理。

+0

谢谢你,它对我来说工作正常。 – vijetha

+0

@vijetha Uplease upvote答案,如果它真的帮助你完全...谢谢 –