Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compass placing or position in a MKMapView? [duplicate]

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.

like image 512
Kevin Avatar asked Jul 10 '16 03:07

Kevin


2 Answers

You can do this by setting the compass visibility to false and then adding a new compass

mapView.showsCompass = false

let compassBtn = MKCompassButton(mapView:mapView)
compassBtn.frame.origin = CGPoint(x: self.view.frame.maxX - 40, y: 20)
compassBtn.compassVisibility = .adaptive
view.addSubview(compassBtn)

You can use adaptive visibility so your new compass will behave like the original one.

like image 77
Wesley Skeen Avatar answered Nov 15 '22 08:11

Wesley Skeen


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)
        }
    }
}
like image 39
G. Veronika Avatar answered Nov 15 '22 07:11

G. Veronika