将 searchbar/button/ANYTHING 放在 google 地图视图之上

Putting a searchbar/button/ANYTHING on top of a google maps view

let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
mapView.delegate = self
mapView.isMyLocationEnabled = true
view = mapView
    search.delegate = self
    view.insertSubview(searchbar, aboveSubview: view)
    view.bringSubview(toFront: searchbar)// view that UISearchBar is in
    view.bringSubview(toFront: search) // actual searchBar

我尝试了各种方法来让 searchBar 出现。 mapView 未连接到 Storyboard 中的 CityViewController,只是在此处以编程方式为 CityViewController.The Storyboard 提供了一个视图,其中的 SearchBar 位于其中。 google 地图在程序中加载正常,但 searchBar 在程序运行时从不显示,而是在故事板上。如果我也将 mapView 添加为子视图,则 mapView 不再显示。

编辑:我已将搜索栏放入 UI 视图到 ViewController 的主视图中。如果我添加约束,则不会出现搜索栏。但是,如果我这样做的话。但是,我无法在搜索栏内输入内容。我已经编辑了代码来显示这一点。

试试这个方法。将搜索栏拖放到视图控制器上。将其前导、尾随和顶部设置为 0。将恒定高度设置为 50。

然后,拖放 google 地图视图的 UIView。在 Class Inspector 中将其 class 设置为 GMSMapView。查看屏幕截图。