子类 MKAnnotationView
有人曾经成功重写过 MKAnnotationView
中的 setDragState
方法吗? 如果我尝试使用“mkannotationview setDragState
”在谷歌上搜索它,我只会得到三个点击!其中之一是我在 stackoverflow 上的另一篇文章;)
参考文献说,当子类化 MKAnnotationView 时,子类必须关心拖动状态。但它没有说具体如何做。仅将 DragState 设置为 MKAnnotationViewDragStateDragging
或者更确切地说 MKAnnotationViewDragStateCanceling
似乎还不够。因为如果我这样做,例如问题之一是地图视图没有收到 mapView:annotationView:didChangeDragState:fromOldState:
委托函数。
我尝试通过在超类中设置 DragState 来覆盖它。但此时会发生其他错误:例如,如果我拖动annotationView并且手指离开屏幕,应用程序就会崩溃,并显示“无法删除键路径拖动状态的观察者”(但我的子类没有我所知道的任何观察者) 。所以看来还有其他事情需要照顾。
在苹果开发者论坛上的这篇文章https://devforums.apple.com/message/203107#203107 aroonicus,一个来自苹果的人,提到你必须重写 [MKAnnotationView setDragState:] 但遗憾的是他没有告诉你如何去做。
有人可以帮忙吗?有人知道如何重写 setDragState 吗?有人创建了 MKAnnotationView 的工作子类来覆盖 setDragState 吗?
再见,
本
Did somebody ever override successfully the method setDragState
in MKAnnotationView
?
If I try to google for it with "mkannotationview setDragState
" I only get three hits! One of them is my other post on stackoverflow ;)
The reference says that when subclassing MKAnnotationView
the subclass has to care about the dragstate. But it does not say how to exactly. Only setting the dragstate to MKAnnotationViewDragStateDragging
or rather MKAnnotationViewDragStateCanceling
seems not to be enough. Because if I just do that, one of the issues for example is that the mapview does not receive the mapView:annotationView:didChangeDragState:fromOldState:
delegate function.
I tried to override it by setting the dragState also in the super class. But at this point other errors occur: For example if I drag the annotationView and my finger runs off the screen, the app crashes with something like "can not remove observer for keypath dragstate" (but my subclass does not any observers I know about). So it seems to that there are other things to care of.
In this post on apple developer forum https://devforums.apple.com/message/203107#203107 aroonicus, a guy from apple, mentions that you have to override [MKAnnotationView setDragState:] but sadly he does not tell how to.
Can anybody help? Does anybody know howto override setDragState? Did anybody created a working subclass of MKAnnotationView overriding setDragState?
Bye,
Ben
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
参考这个帖子
请参阅第二个答案,其中使用自定义注释视图类来覆盖现有的注释视图类。它可以
子类化 MKAnnotationView 并覆盖 setDragState
Refer this thread
refer to the second answer where a custom annotation view class is used to override the existing one. It works
Subclassing MKAnnotationView and overriding setDragState
可以使用自定义注释。请参阅以下示例项目: http://digdog.tumblr.com /post/1616858395/note-about-mapkitdraganddrop-3-2
It's possible using custom annotations. See the following sample project: http://digdog.tumblr.com/post/1616858395/note-about-mapkitdraganddrop-3-2