本文介绍了如何重新放置MKMapView的指南针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想移动MKMapView指南针.我想通过以下方式获取参考:

I want to move the MKMapView compass. I wanted to get a reference for it by something like this:

let compassView = mapView.subviews.filter {$0 is NSClassFromString("MKCompassView")}

但是,编译器抱怨使用未声明的类型'NSClassFromString'".我该如何解决此代码?

However the compiler complains " Use of undeclared type 'NSClassFromString' ".How can I fix this code?

推荐答案

iOS 11

您应该使用MKCompassButton解释新内容的文档: WWDC 2017新的MapKit演示文稿.

you should use MKCompassButton, doc explaining the new stuff: WWDC 2017 new MapKit presentation.

let compassButton = MKCompassButton(mapView:mapView)
compassButton.frame.origin = CGPoint(x: 20, y: 20)
compassButton.compassVisibility = .visible
view.addSubview(compassButton)

iOS< 11

您可能会尝试使用String(describing:),例如:

You might try to use String(describing:), something like:

if let compassButton = (mapView.subviews.filter { String(describing:$0).contains("MKCompassView") }.first) {
   print(compassButton)
}

这篇关于如何重新放置MKMapView的指南针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 04:34