ios - 将搜索栏/按钮/任何东西放在谷歌地图 View 的顶部

标签 ios iphone swift google-maps-sdk-ios

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。Storyboard 只有一个 View ,SearchBar 位于其中。谷歌地图在程序中加载正常,但当程序运行但在 Storyboard上时,searchBar 永远不会显示。如果我也将 mapView 添加为 subview ,则 mapView 不再显示。

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

最佳答案

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

然后,拖放用于谷歌地图 View 的 UIView。在类检查器中将其类设置为 GMSMapView。查看屏幕截图。

UIView

关于ios - 将搜索栏/按钮/任何东西放在谷歌地图 View 的顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50243514/

相关文章:

ios - 如何创建一个像 UILabel 一样具有 intrinsicContentSize 的 View ?

ios - Swift 3.0 中的 NSIndexPath 和 IndexPath

iphone - 在另一个应用程序中模拟 iPhone 应用程序?

swift - 如何将嵌套对象添加到核心数据中的现有对象

ios - 当另一个 UIViewController(在 UINavigationController 内)显示时,UIViewController 不调整内容插入

ios - 在 swift 中创建简单的线程会出错

iphone - 录制的音频文件

ios - 如何在 ARkIt 2 中将图像包裹在 3d 对象上?

ios - swift 用户界面 : How to get a Navigation Title aligned with Back Button

ios - 获取我的 UIBarButtonItem 在 iOS 11 中的位置