注释没有按照我提供的顺序掉落在地图视图上
我开发了一个应用程序,它使用地图视图,该视图在同一位置有多个注释,但它不会删除我提供注释顺序的引脚。我从数组中添加了注释,但它没有显示相同的顺序。我需要第一个对象 [注释] 位于该位置的顶部。当用户点击注释时,它应该将第一个对象显示为标注。任何建议做同样的事情。
谢谢 我已经尝试过这种方法,但没有运气..
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
for (MKAnnotationView *view in views) {
if ([[view annotation] isKindOfClass:[Annotation class]]) {
Annotation *customAnnotation = (Annotation*) [view annotation];
if ([customAnnotation markerID]==0)
[[view superview] bringSubviewToFront:view];
else {
[[view superview] sendSubviewToBack:view];
}
}
}
}
I developed an application, which uses the map view, which has multiple annotations at the same location, but it is not dropping the pins which I provided the order for the annotations. I added annotations from the array, but it is not showing the same order. I need the first object [annotation] to be the top on the location. when user taps on the annotation, it should show the first object as callout. Any suggestions to do the same.
Thanks
I have already tried this approach, but no luck..
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
for (MKAnnotationView *view in views) {
if ([[view annotation] isKindOfClass:[Annotation class]]) {
Annotation *customAnnotation = (Annotation*) [view annotation];
if ([customAnnotation markerID]==0)
[[view superview] bringSubviewToFront:view];
else {
[[view superview] sendSubviewToBack:view];
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
注释可以按任意顺序添加,并且可以像表视图中的单元格一样在视图中添加或删除。因此 z 层可能会以您可能不希望的方式变化。
这是一些可能对您有帮助的示例代码。我有一张显示搜索结果图钉的地图。它们分为正常结果和收藏夹。我希望收藏夹始终位于顶部或其他图钉上。我还有一个“矩形”来突出显示选定的地图图钉,我总是希望它位于所有注释的顶部。我使用此代码将不同类型的注释放入正确的 z 层顺序中:
Annotations can put added in an arbitrary order, and can be added or removed from the view the same way cells are in a table view. So the z-layer can vary in a way you might not want.
Here is some sample code that might help you. I have a map that displays pins for search results. They are divided into normal results and favorites. I want the favorites to always be on top or the other pins. I also have a "recticle" to highlight a selected map pin, and I always want this to be on top of all of the annotations. I use this code to get different types of annotations into the right z-layer order: