【问题标题】:How to display sub view or button on top of Google maps Xcode如何在 Google 地图 Xcode 顶部显示子视图或按钮
【发布时间】:2015-10-22 13:34:57
【问题描述】:

我试图在 Google 地图上添加一个按钮。我尽我所能,但没有人能帮助我。在 Xcode 预览中,它显示在顶部,但在运行应用程序后,它位于谷歌地图下方。

应用运行后的图片

它在 XCODE 中的样子

地图代码

import UIKit
import GoogleMaps

class HomeViewController: UIViewController, CLLocationManagerDelegate {
    @IBOutlet weak var scrollView: UIScrollView!
    @IBAction func refreshLocation(sender: AnyObject) {
        locationManager.startUpdatingLocation()

    }
@IBOutlet weak var gMapView: GMSMapView!


let locationManager = CLLocationManager()




override func viewDidLoad() {
    super.viewDidLoad()
    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
    locationManager.requestAlwaysAuthorization()
  locationManager.startUpdatingLocation()
    self.scrollView.contentSize=CGSizeMake(320, 700)


            let camera = GMSCameraPosition.cameraWithLatitude(15.4989, longitude: 73.8278, zoom: 17)

            gMapView.camera = camera
            gMapView.myLocationEnabled = true

            self.view.addSubview(gMapView)
            let marker = GMSMarker()

            marker.map = self.gMapView

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

}

extension HomeViewController {
    func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
        if status == CLAuthorizationStatus.AuthorizedAlways {
            locationManager.startUpdatingLocation()

        gMapView.myLocationEnabled = true

        gMapView.settings.myLocationButton = true
    }
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    if let location = locations.first {
        gMapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)

        locationManager.stopUpdatingLocation()

    }
}



}

【问题讨论】:

  • 另外,如果您以编程方式操作子视图,请分享代码。有关约束的信息也会有所帮助。
  • 我正在使用自动布局做所有事情。没有任何程序。我是 iOS 新手
  • 是的,我可以看到您正在使用自动布局。在您创建地图的位置共享代码。还告诉我们你在 control.png 上使用了哪些约束(我假设你想把哪个 Imageview 放在首位)。此外,UIImageView 不是 UIButton。
  • 我已经更新了代码
  • 在分配 view=mapView 之前需要添加子视图。

标签: ios xcode swift google-maps swift2


【解决方案1】:

我找到了答案

self.view.bringSubviewToFront(self.view_name)

您需要在父视图上调用bringSubviewToFront。

【讨论】:

    【解决方案2】:

    您是否使用以下方法?如果是,请确保您为 mapview 提供框架,因此请尝试提供与您在情节提要中提供的相同的框架。

    [GMSMapView mapWithFrame:(CGRect) 相机:(GMSCameraPosition *)];

    【讨论】:

    • 其实我用的是swift,我用的是这个gMapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0,lookingAngle: 0)
    • @O-mkar 你给 MapView 什么框架?
    • 如果你不使用那个方法,不需要给框架。
    • 好的,尝试通过给gMapView提供frame来解决。在使用语法 addSubview 或给出出口 gMapView 之前先给出框架,因此无需使用 addSubview 方法
    猜你喜欢
    • 1970-01-01
    • 2023-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多