swift - 在 MapBox 层 iOS 上添加搜索栏
问题描述
我正在尝试在 iOS 上的 MapBox 导航地图中添加搜索栏,但遇到了一些麻烦。在这种情况下,我试图以编程方式进行,因为我对故事板没有很好的处理。我也尝试过使用 zIndex,但仍然没有显示搜索栏。
这是我到目前为止的代码:
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)
推荐阅读
- java - 在物理设备上测试时工具栏标题保持黑色
- django - Django / React Router DOM - 登陆 django 中未指定的 url
- asp.net-core - 在 asp.net core 中获取 HEIC 图像的属性
- python - 如果输入宽度和高度与调整输入和宽度的大小相同,cv2.resize() 会做什么?
- django - Django:为相关对象生成查询集,同时保留注释
- java - 如何使用 utlizie stringbuilder 添加所有其他字符并在空格处重新启动?
- reactjs - 单击搜索栏时导航到新页面
- r - R中字符串中某些动态变化之间的高级替换
- apache-spark - Apache Kafka/Spark/Streaming 方法
- java - cron没有运行java程序