【问题标题】:Google map does not fit in SubView properly谷歌地图不适合 SubView
【发布时间】:2017-11-16 07:33:37
【问题描述】:

我正在使用 Google 地图,但在 subView 中未正确设置。 我正在使用 swift 3。

@IBOutlet weak var mapSubView: UIView!
 var mapView:GMSMapView!
var placesClient: GMSPlacesClient!

我在viewDidLoad中使用了以下代码:

let camera = GMSCameraPosition.camera(withLatitude: 28.616536, longitude: 77.379552, zoom: 12.0)
mapView = GMSMapView.map(withFrame: mapSubView.bounds, camera: camera)
mapSubView.addSubview(mapView)
mapView.delegate = self
self.drawPath()
placesClient = GMSPlacesClient.shared()

我的模拟器截图:

您在谷歌地图附近的右侧看到了空白

还有我故事板的截图:

【问题讨论】:

    标签: ios swift swift3 google-maps-sdk-ios


    【解决方案1】:

    viewDidLoad 中,您的视图没有完全呈现,所以这条线

    mapView = GMSMapView.map(withFrame: mapSubView.bounds, camera: camera)
    

    将根据特定时间的边界设置 mapView 的大小。有几个解决方法。一种是稍后渲染您的 mapView,例如在viewWillAppear。另一种是在故事板中创建一个UIView,设置它的约束,使其类为GMSMapView并连接一个@IBOutlet。此外,您可以使用autoresizingMask 修复它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-15
      • 1970-01-01
      • 2014-12-24
      • 2017-11-01
      • 2015-08-08
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多