How to reposition compass of MKMapView?

前端 未结 3 1972
说谎
说谎 2021-01-19 10:38

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 NSClassFrom         


        
3条回答
  •  再見小時候
    2021-01-19 11:04

    iOS 11

    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

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

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

提交回复
热议问题