问题
I have a situation where I have to reposition the map box compass view to a different location. The compassView is now rotating when I rotate the map taking some other point as its(compassView) axis and gives me a weird outcome. Screenshot is attached, the black mapBox default compass icon is rotating, refer the screenshots. Is this a MapBox sdk bug? if so, are there any work around? And tweaks? I am confused. Expert advices needed. Thanks in advance.
回答1:
Hey I found another method where I will get the same result of the compass in the map box. I've placed a button and then
func mapViewRegionIsChanging(_ mapView: MGLMapView) {
compassViewUpdate(direction: Double(bearing))
inside compassViewUpdate method
func compassViewUpdate(direction:Double) {
self.compassButton.transform = CGAffineTransform(rotationAngle: CGFloat(-direction.degreesToRadians))
}
@Sarang here is a work around. Happy coding.
回答2:
A built-in approach that's available in the Mapbox iOS SDK. Using these methods
to move the compass will avoid the distortion caused by .frame
and .center
changes.
Generally Changing the CompassView Location
mapView.compassViewPosition = .bottomLeft
mapView.compassViewPosition = .bottomRight
mapView.compassViewPosition = .topLeft
mapView.compassViewPosition = .topRight
Use compassViewPosition
to get the compass generally where you want it on the
screen.
Fine Tuning the CompassView Location
mapView.compassViewMargins = CGPoint(x: 64, y: 16)
Default x, y = 8, 8
The margin is to the outside/along the border of the view. So for .bottomLeft
the compass view will move 56 right and 8 up versus .topRight
where the
compass will move 56 left and 8 down.
回答3:
try changing the compassView.center instead of changing its origin or frame. I am guessing it has approximately 40 pixels width x height, and I changed to bottom left using the following:
let centerCalc = CGRect(x: 5, y: frame.height - 45, width: 40, height: 40)
compassView.center = CGPoint(x: centerCalc.midX, y: centerCalc.midY)
It should work!
来源:https://stackoverflow.com/questions/49130712/mapbox-default-compassview-when-repositioned-gives-weird-outcome