如何在IOS上管理MKAnnotationView的拖放? [英] how to manage drag and drop for MKAnnotationView on IOS?

查看:24
本文介绍了如何在IOS上管理MKAnnotationView的拖放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在没有 InterfaceBuilder 的情况下工作.

我有一个 MKAnnotationView 实例,setDraggable 位于 YES,在我的 MKMapView 中显示了我的注释视图,我可以拖放它.

执行放置操作时如何执行方法?在这种方法中,我需要注释视图的新坐标.

解决方案

如果你已经用 setCoordinate 方法正确设置了你的 MKAnnotation 对象,那么在 didChangeDragState 方法中,新的坐标应该已经在注解对象中了:

p>

- (void)mapView:(MKMapView *)mapViewannotationView:(MKAnnotationView *)annotationViewdidChangeDragState:(MKAnnotationViewDragState)newStatefromOldState:(MKAnnotationViewDragState)oldState{if (newState == MKAnnotationViewDragStateEnding){CLLocationCoordinate2D droppedAt = annotationView.annotation.coordinate;NSLog(@"dropped at %f,%f", droppedAt.latitude, droppedAt.longitude);}}

有关参考,请参阅 文档在这里.如果您的应用程序需要在 4.x 之前的操作系统中运行,则拖动需要更多的手动工作.文档中的链接还指向了一个示例,说明如何在需要时执行此操作.

I'm working without InterfaceBuilder.

I've an instance of MKAnnotationView with setDraggable on YES, In My MKMapView my annotation view is displayed and I can drag and drop it.

How can I execute an method when the drop action is performed? In this method I need the new coordonates of my annotation view.

解决方案

If you've setup your MKAnnotation object with a setCoordinate method properly, then in the didChangeDragState method, the new coordinate should already be in the annotation object:

- (void)mapView:(MKMapView *)mapView 
        annotationView:(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);
    }
}

For reference, see the "Marking Your Annotation View as Draggable" section in the docs here. If your app needs to work in an OS earlier than 4.x, the dragging requires more manual work. The link in the docs also points to an example of how to do that if you need to.

这篇关于如何在IOS上管理MKAnnotationView的拖放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆