Disable compass on MKMapView

2019-03-18 10:04发布

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?

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.

8条回答
劫难
2楼-- · 2019-03-18 10:38

Create a wrapper UIView with the frame you want for your map and clipsToBounds set to YES (or equivalently, Clip Subviews set in Interface Builder). Then put your MKMapView inside that wrapper view, with the y co-ordinate of the map's frame set to, for example, -80, and the height of the map set such that its vertical center is aligned with its parent.

Then the compass will be displayed but you cannot see it, because it is above the top of its parent view - problem solved.

查看更多
对你真心纯属浪费
3楼-- · 2019-03-18 10:43

Here is solution for Swift 4:

mapView.compassView.isHidden = true
查看更多
登录 后发表回答