Swift 在MapBox图层iOS上添加搜索栏
我正在尝试在iOS上为MapBox的导航地图添加搜索栏,但遇到了一些问题。在本例中,我试图以编程的方式来实现它,因为我在故事板上没有很好的处理能力。我也尝试过和zIndex混在一起,但仍然没有搜索栏出现 以下是我目前掌握的代码:Swift 在MapBox图层iOS上添加搜索栏,swift,mapbox,Swift,Mapbox,我正在尝试在iOS上为MapBox的导航地图添加搜索栏,但遇到了一些问题。在本例中,我试图以编程的方式来实现它,因为我在故事板上没有很好的处理能力。我也尝试过和zIndex混在一起,但仍然没有搜索栏出现 以下是我目前掌握的代码: class ViewController: UIViewController, UISearchBarDelegate, MGLMapViewDelegate { var mapView: NavigationMapView! lazy var dire
class ViewController: UIViewController, UISearchBarDelegate, MGLMapViewDelegate {
var mapView: NavigationMapView!
lazy var directions: DirectionsManager = DirectionsManager()
var searchBar: UISearchBar!
override func viewDidLoad() {
super.viewDidLoad()
// Setup mapbox
let styleURL = URL(string: "style")
mapView = NavigationMapView(frame: view.bounds, styleURL: styleURL)
view.addSubview(mapView)
mapView.delegate = self
mapView.showsUserLocation = true
mapView.setUserTrackingMode(.follow, animated: true)
mapView.localizeLabels()
self.searchBar = UISearchBar()
mapView.addSubview(searchBar)
}
@erikpartridge,这不是mapbox的问题,您需要为UISearchBar设置框架,如下所示
self.searchBar = UISearchBar(frame: CGRect(x: 15, y: 50, width: (view.bounds.width-30), height: 50))
mapView.addSubview(searchBar)