mis*_*Not 3 mapkit mkmapview ios swift ios11
我想移动MKMapView指南针.我希望通过以下方式获得它的参考:
let compassView = mapView.subviews.filter {$0 is NSClassFromString("MKCompassView")}
Run Code Online (Sandbox Code Playgroud)
然而,编译器抱怨"使用未声明的类型'NSClassFromString'".我该如何修复此代码?
iOS 11
你应该使用MKCompassButton,doc解释新的东西:WWDC 2017新的MapKit演示文稿.
let compassButton = MKCompassButton(mapView:mapView)
compassButton.frame.origin = CGPoint(x: 20, y: 20)
compassButton.compassVisibility = .visible
view.addSubview(compassButton)
Run Code Online (Sandbox Code Playgroud)
iOS <11
您可能会尝试使用String(describing:),例如:
if let compassButton = (mapView.subviews.filter { String(describing:$0).contains("MKCompassView") }.first) {
print(compassButton)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1518 次 |
| 最近记录: |