禁用MKMapView上的指南针 [英] Disable compass on MKMapView

查看:137
本文介绍了禁用MKMapView上的指南针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中使用MapView来显示一些注释。在iOS 7中,指南针随机出现在地图上。我无法重现错误,因为它随机出现,但我想禁用它。
有关如何禁用它的任何想法?

I am using a MapView in my app to show some annotations. In iOS 7 a compass appears randomly on the map. I can't reproduce the error because it appears randomly but I want to disable it. Any ideas how to disable it?

更新:我发现不是随机出现,而是出现在特定手势上。当您使用2个手指并向右滑动而另一个向左滑动时。

Update: I found out is not appears randomly but on a specific gesture. When you use 2 fingers and slide one right and the other left.

推荐答案

您可以使用 showsCompass property:

You can disable the compass easily on OSX 10.9 / iOS 9 and later with the showsCompass property:

yourMapView.showsCompass = NO;

在iOS 8或更早版本中,您的选择是:

On iOS 8 or earlier, your choices are:


  1. 将其吸收并使用它。

  1. Suck it up and live with it.

使用hack,如:

  • position the map to hide the compass offscreen (credit goes to Alex Wien), or

走看地图的视图层次结构,找到代表指南针的视图并将其删除(信用转到David Topolansky)。

walk the view hierarchy of the map to find the view representing the compass and remove it (credit goes to David Topolansky).

如果您没有以编程方式旋转地图并且尚未旋转,请完全禁用旋转,使用

If you're not rotating the map programatically and it hasn't already been rotated, disable rotation entirely, using

mapView.rotateEnabled = NO;

指南针仅在地图旋转时显示,因此,请确保指南针是从来没有被触发过。

The compass only shows up when the map is rotated, so by doing this you ensure that the compass is never triggered.

我不清楚为什么苹果等待这么长时间才能让指南针隐藏在iOS上,而且没有以上选项是理想的。选择你认为最不好的情况。

It's not clear to me why Apple waited so long to allow hiding the compass on iOS, and none of the options above are ideal. Pick whichever you think is the least bad in your case.

这篇关于禁用MKMapView上的指南针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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