iOS - MKMapView 仅显示特定缩放级别的注释
我有一个带有一些自定义注释的 MKMapView,当地图缩小得很远时,这些注释看起来不太好。
是否可以仅在地图处于特定缩放级别时显示/添加它们?
I have a MKMapView with some custom annotations that don't look that great when the map is zoom far out.
Is it possible to only show/add them when the map is at a certain zoom level?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用马科的回答我得出了这个解决方案。
每次区域更改时,我都会更改 ViewController 的属性
isAtBigZoom
。然后在属性的
didSet
处,我执行此代码。如果您还想从隐藏注释开始,只需将 alpha 更改代码添加到
viewForAnnotation
方法中即可。效果很好,我没有注意到性能方面的大问题。尽管这可能会随着注释数量的增加而改变......
Using Marko's answer I came to this solution.
Everytime region changes, I change the
ViewController's
propertyisAtBigZoom
.Then at
didSet
of the property, I execute this code.If you also want to start with the annotations hidden, just add the alpha changing code to
viewForAnnotation
method.Works great and I haven't noticed big issues with performance. Though that may change with the increasing number of annotations...
获取地图缩放级别
您可以通过MKMapView 的属性 。您还会收到区域更改事件的通知
通过实现 MKMapViewDelegate 方法并在此处设置委托
,您可以检查当前的缩放级别。我不建议在缩放/平移时删除或添加所有注释,因为这确实会影响应用程序的性能。我还没有真正尝试过将 alpha 设置为 0.0 或 MKAnnotationView 上的隐藏属性,但这可能是您最好的选择。
You can get the map zoom level via
property of the MKMapView. also you get the notifications for region changing events
by implementing the MKMapViewDelegate method and setting the delegate
here you can check what your current zoom level is. I don't recommend removing or adding all the annotations while zooming / panning since that could really effect the app performance. I haven't really tried setting alpha to 0.0 or hidden property on MKAnnotationView, but that could be your best bet.