Search code examples
swiftmkmapview

Compass placing or position in a MKMapView?


I am coding one Location based App by Swift.

I make my MapView can show Compass, but I would like to change the compass location from the right-up corner to the left-down corner.

Does any expert know how to move it?

Thank you in advanced.


Solution

  • You can try to change this:

    mapView.layoutMargins 
    

    Or subclass the MKMapView component:

    import MapKit
    
    class MyMapView: MKMapView {    
        override func layoutSubviews() {
            super.layoutSubviews()
    
            if let compassView = self.subviews.filter({ $0.isKindOfClass(NSClassFromString("MKCompassView")!) }).first {
                compassView.frame = CGRectMake(15, 30, 36, 36)
            }
        }
    }