【问题标题】:Mapbox default compassView when repositioned gives weird outcome重新定位时 Mapbox 默认的 compassView 会产生奇怪的结果
【发布时间】:2018-03-06 12:20:41
【问题描述】:
我有一种情况,我必须将地图框罗盘视图重新定位到不同的位置。当我以其他点为(compassView)轴旋转地图时,compassView 现在正在旋转,这给了我一个奇怪的结果。附上截图,黑色mapBox默认的指南针图标是旋转的,参考截图。这是 MapBox sdk 错误吗?如果是这样,有什么解决方法吗?和微调?我很困惑。需要专家建议。提前致谢。
【问题讨论】:
标签:
ios
swift
xcode
mapbox
【解决方案1】:
嘿,我找到了另一种方法,可以在地图框中获得与指南针相同的结果。我已经放置了一个按钮,然后
func mapViewRegionIsChanging(_ mapView: MGLMapView) {
compassViewUpdate(direction: Double(bearing))
在 compassViewUpdate 方法中
func compassViewUpdate(direction:Double) {
self.compassButton.transform = CGAffineTransform(rotationAngle: CGFloat(-direction.degreesToRadians))
}
@Sarang 这里是一个解决方法。编码愉快。
【解决方案2】:
Mapbox iOS SDK 中提供的一种内置方法。使用这些方法
移动指南针将避免.frame和.center造成的失真
变化。
一般更改 CompassView 位置
mapView.compassViewPosition = .bottomLeft
mapView.compassViewPosition = .bottomRight
mapView.compassViewPosition = .topLeft
mapView.compassViewPosition = .topRight
使用compassViewPosition 将指南针放在您想要的位置
屏幕。
微调 CompassView 位置
mapView.compassViewMargins = CGPoint(x: 64, y: 16)
默认 x, y = 8, 8
边距位于视图的外部/沿视图的边界。所以对于.bottomLeft
与.topRight 相比,指南针视图将向右移动 56 和向上移动 8
指南针将向左移动 56,向下移动 8。
【解决方案3】:
尝试更改 compassView.center 而不是更改其原点或框架。我猜它的宽度 x 高度大约为 40 像素,我使用以下代码更改为左下角:
let centerCalc = CGRect(x: 5, y: frame.height - 45, width: 40, height: 40)
compassView.center = CGPoint(x: centerCalc.midX, y: centerCalc.midY)
应该可以了!