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.
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.
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)
}
}
}
MKCompassView
in the subviews of my instance of MKMapView. The compass is enabled and showing but inaccessible. –
Mcpherson MKCompassView
, and MKCompassButton
is only available publicly starting iOS 11. This screams private API access to me. –
Carcanet mapView.layoutMargins = view.safeAreaInsets
worked best for me. –
Zumstein mapView.layoutMargins = UIEdgeInsets(top: 64, left: 0, bottom: 0, right: 8)
–
Dichogamy 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.
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)
}
}
}
MKCompassView
in the subviews of my instance of MKMapView. The compass is enabled and showing but inaccessible. –
Mcpherson MKCompassView
, and MKCompassButton
is only available publicly starting iOS 11. This screams private API access to me. –
Carcanet mapView.layoutMargins = view.safeAreaInsets
worked best for me. –
Zumstein mapView.layoutMargins = UIEdgeInsets(top: 64, left: 0, bottom: 0, right: 8)
–
Dichogamy © 2022 - 2024 — McMap. All rights reserved.