分层 table 视图和 google 地图视图 iOS Swift
Layering a table view and a google map view iOS Swift
我正在尝试使用 ios 中的 google 地图 sdk 设置地图搜索。到目前为止,我的自动完成搜索工作正常,当我搜索时,结果显示在 table 视图中。我希望能够单击 table 视图中的一个单元格并显示地图,然后当用户返回搜索框时再次显示 table。我这样做的策略是在同一个视图控制器中将 mapview 和 table 视图分层,然后 show/hide 或将任何一个视图推到顶部。但是,因为 google 地图不是 mapkit 的一部分,所以我不确定我是否可以像这样操作它。如果您知道执行此操作的简单方法,请告诉我。将视图设置为 tableview 也会导致黑屏
mapView.hidden 只是黑屏
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.dataSource = self
self.tableView.delegate = self
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
self.tableView.tableHeaderView = controller.searchBar
return controller
})()
view.bringSubviewToFront(self.tableView)
placesClient = GMSPlacesClient()
var camera = GMSCameraPosition.cameraWithLatitude(-33.86,
longitude: 151.20, zoom: 6)
var mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
//mapView.hidden = true
mapView.myLocationEnabled = true
self.view = mapView
self.view = self.tableView
var marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
}
我正在使用 google 地图 cocoapod
这取决于它们在视图控制器的子视图列表中的顺序。如果mapView
和tableView
都是根view
的直接子视图,你可以只调用insertSubview:belowSubview:
[self.view insertSubview:mapView belowSubview:tableView];
反之亦然。
我发现我必须添加自己的子视图,将该子视图的 class 更改为 GMSMapview 并将地图分配给该子视图。
var camera = GMSCameraPosition.cameraWithLatitude(-33.86,
longitude: 151.20, zoom: 6)
var mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.myLocationEnabled = true
self.mapSubView.camera = camera
self.mapSubView = mapView
我正在尝试使用 ios 中的 google 地图 sdk 设置地图搜索。到目前为止,我的自动完成搜索工作正常,当我搜索时,结果显示在 table 视图中。我希望能够单击 table 视图中的一个单元格并显示地图,然后当用户返回搜索框时再次显示 table。我这样做的策略是在同一个视图控制器中将 mapview 和 table 视图分层,然后 show/hide 或将任何一个视图推到顶部。但是,因为 google 地图不是 mapkit 的一部分,所以我不确定我是否可以像这样操作它。如果您知道执行此操作的简单方法,请告诉我。将视图设置为 tableview 也会导致黑屏
mapView.hidden 只是黑屏
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.dataSource = self
self.tableView.delegate = self
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
self.tableView.tableHeaderView = controller.searchBar
return controller
})()
view.bringSubviewToFront(self.tableView)
placesClient = GMSPlacesClient()
var camera = GMSCameraPosition.cameraWithLatitude(-33.86,
longitude: 151.20, zoom: 6)
var mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
//mapView.hidden = true
mapView.myLocationEnabled = true
self.view = mapView
self.view = self.tableView
var marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
}
我正在使用 google 地图 cocoapod
这取决于它们在视图控制器的子视图列表中的顺序。如果mapView
和tableView
都是根view
的直接子视图,你可以只调用insertSubview:belowSubview:
[self.view insertSubview:mapView belowSubview:tableView];
反之亦然。
我发现我必须添加自己的子视图,将该子视图的 class 更改为 GMSMapview 并将地图分配给该子视图。
var camera = GMSCameraPosition.cameraWithLatitude(-33.86,
longitude: 151.20, zoom: 6)
var mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.myLocationEnabled = true
self.mapSubView.camera = camera
self.mapSubView = mapView