如何在swift中更改Google Map的myLocationButton的位置

问题描述 投票:2回答:3

我是swift的新手,并制作了一个应用程序,我正在使用Gogle Map SDK for iOS。我使用了myLocationButton,它最初设置在右下角。我只是想改变它的立场。

enter image description here

我想将MyLocationButton放在地球按钮图像现在显示的位置。

提前致谢。

ios swift google-maps swift2
3个回答
2
投票

Google Maps SDK for iOS提供了一些内置的UI控件,类似于Google Maps for iOS应用程序中的控件。每个控件具有相对于地图边缘的预定位置。您可以通过填充地图将控件移离边缘。 Google Map旨在填充GMSMapView定义的整个区域。要向地图添加填充,请创建UIEdgeInsets对象并将其传递给GM​​SMapView.padding属性。

// Insets are specified in this order: top, left, bottom, right
UIEdgeInsets mapInsets = UIEdgeInsetsMake(100.0, 0.0, 0.0, 300.0);
mapView.padding = mapInsets;

有关更多信息,您可以查看这个相关的SO问题2696836416879694


1
投票
mapView.padding = UIEdgeInsets(top: 0, left: 0, bottom: 10, right:0)

Swift 3.0,更改位置按钮


1
投票

Swift 2.3:仅移动位置按钮的解决方案。我正在使用pod'GoogleMaps','〜> 2.1'。

for object in mapView.subviews {
    if object.theClassName == "GMSUISettingsView" {
        for view in object.subviews {
            if view.theClassName == "GMSx_QTMButton" {
              var frame = view.frame
              frame.origin.y = frame.origin.y - 110 // Move the button 110 up
              view.frame = frame
            }
        }
    }
}

扩展以获取类名。

extension NSObject {
  var theClassName: String {
    return NSStringFromClass(self.dynamicType)
  }
}

我会尽快将此代码更新到Swift 3.0。 :)

Swift 4.0:

public extension NSObject {
    public var theClassName: String {
        return NSStringFromClass(type(of: self))
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.