【问题标题】:Not being able to size Google Map in UIView无法在 UIView 中调整 Google Map 的大小
【发布时间】:2016-07-08 19:55:12
【问题描述】:

我正在使用 Google Maps SKD,我正在尝试制作适合 UIView 的地图。首先,我添加了一个全屏 UIView,它在我的应用程序中显示 PanoramaView。效果很好,这里是变量声明:

 @IBOutlet weak var streetViewer: UIView!
 @IBOutlet weak var gmapViewer: UIView!

 var panoView: GMSPanoramaView!
 var mapView: GMSMapView!

然后在 viewDiDLoad() 中创建全景图并将其添加为streetViewer 的子视图:

 panoView = GMSPanoramaView(frame: CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height))
 panoView.delegate = self
 panoView.moveNearCoordinate(CLLocationCoordinate2D(latitude: -33.732, longitude: 150.312))
 streetViewer.addSubview(panoView)
 streetViewer.sendSubviewToBack(panoView)

现在我正在尝试对覆盖大约一半屏幕并在panoView 层上显示mapViewUIView 执行相同的操作。在这里,我正在创建地图,将其添加为 gmapViewer 的子视图,最后将其添加为子视图并将其移动到 panoView 的顶部:

 mapView = GMSMapView(frame: CGRectMake(0, 0, gmapViewer.bounds.size.width, gmapViewer.bounds.size.height))
 mapView.delegate = self
 gmapViewer.addSubview(mapView)
 streetViewer.addSubview(gmapViewer)
 panoView.sendSubviewToBack(gmapViewer)

我已为所有 UIView 添加了约束。我还向gmapViewer 添加了一些折纸动画,除了没有填满gmapViewer 的地图外,所有的效果都很好。我认为问题在于mapView = GMSMapView(frame: CGRectMake(0, 0, gmapViewer.bounds.size.width, gmapViewer.bounds.size.height)),但我不明白什么不起作用,因为它适用于panoView

【问题讨论】:

  • 你解决了吗?
  • 你解决了吗?
  • 你解决了吗?
  • @MrMins 我在这里发布了我想要完成的代码,希望对您有所帮助。
  • @Denny 我在这里发布了代码来完成我想要完成的工作,希望对您有所帮助。

标签: swift google-maps uiview subview google-maps-sdk-ios


【解决方案1】:

在将近 5 年之后发布这个问题,因为我觉得这个问题仍然没有答案,我认为我改进了足够的 iOS 程序员,能够回答我自己的问题,我希望这对其他人有所帮助。

我的错误是我试图以编程方式和情节提要混合约束设置时搞砸了,不知道为什么我不简单地使用框架 CGRect(gmapViewer.bounds.size.width/2, 0, gmapViewer.bounds.size.width/2, gmapViewer.bounds.size.height) 设置 mapView。

不管怎样,下面的代码显示了一个全屏的谷歌街景,被半屏大小的谷歌地图视图覆盖。

private let mapView = GMSMapView()
private let streetView = GMSPanoramaView()

override func viewDidLoad() {
    super.viewDidLoad()
    self.view.addSubview(streetView)
    self.view.addSubview(mapView)
    streetView.moveNearCoordinate(CLLocationCoordinate2D(latitude: 37.3317134, longitude: -122.0307466))
}

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    streetView.frame = CGRect(x: 0,
                              y: 0,
                              width: view.bounds.size.width,
                              height: view.bounds.size.height)
    mapView.frame = CGRect(x: view.bounds.size.width/2,
                           y: 0,
                           width: view.bounds.size.width/2,
                           height: view.bounds.size.height)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-05
    • 2012-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多