MKPinAnnotationView的自定义使用
是否可以在与地图无关的应用程序中使用 MKPinAnnotationView 控件。 我不想使用 MKMapView,我只想重用 MKPinAnnotationView 控件并能够将其放置在特定的屏幕坐标处。
谢谢, 克里斯蒂安
Is it possible to use MKPinAnnotationView controls in a application that has nothing to do with maps.
I do not want to use MKMapView, I just want to reuse the MKPinAnnotationView control and be able to drop it at a specific screen coordinate.
Thanks,
Cristian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,它派生自
UIView
,因此理论上似乎是可能的,但如果其超级视图不是 MKMapView,则它可能无法正常运行。我会尝试一下,看看会发生什么(并让我们其他人知道)。或者,创建您自己的 UIView 子类也不会太难,其行为与 MKPinAnnotationView 非常相似。 (我可能会子类化 UIControl,因为您可能希望能够响应用户事件。)
编辑: 我刚刚尝试了一个非常基本的实现,它似乎工作正常。这是我在视图控制器中使用的代码。 MyAnnotation 是一个非常简单的类,它实现了 MKAnnotation 协议。
另一个更新: 嗯,图钉会显示,但即使
draggable = YES
也无法拖动,并且即使canShowCallout = YES
也不会出现标注代码>.这是有道理的,因为这些行为实际上是由地图视图而不是实际的图钉视图控制的。因此,如果您只想在视图上显示带有阴影的图钉,那么它效果很好。如果您想要在地图视图中显示图钉时获得某些功能,则必须在视图或视图控制器中自行实现它。
Well, it derives from
UIView
so it seems possible in theory, but it may not behave properly if its superview isn't a MKMapView. I would try it and see what happens (and let the rest of us know).Alternatively, it wouldn't be too hard to create your own UIView subclass that behaves very similarly to the MKPinAnnotationView. (I would probably subclass UIControl since you probably want to be able to respond to user events.)
EDIT: I just tried a very basic implementation and it seems to work fine. Here's the code I used in my view controller. MyAnnotation is a very simple class that implements the MKAnnotation protocol.
Another update: Well, the pin displays, but it's not draggable even if
draggable = YES
, and the callout doesn't appear even ifcanShowCallout = YES
. This makes sense given that these behaviors are actually controlled by the map view, and not the actual pin view.So if you just want to display a pin with a shadow on your view, it works great. If you want some of the functionality you get when the pin is displayed in a map view, you have to implment it yourself in your view or view controller.