ios - 使用 Swift 在 Mapbox 中为弹出窗口(语音气泡)创建按钮
问题描述
我用相同的代码发布了另一个问题,但这个问题是不同的。
我想在显示的语音气泡的右下角添加按钮
Hello World!
Welcome to my marker!
我想知道如何将按钮放在那里,但是如果您想知道按钮会做什么,其中一个会跟踪其他用户对气泡的投票数,另一个会向另一个用户发送请求.
另外,我发现这个例子看起来像是实现了一个不同版本的气泡(弹出),可能更好用
import Mapbox
class ViewController: UIViewController, MGLMapViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let mapView = MGLMapView(frame: view.bounds)
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
// Set the map’s center coordinate and zoom level.
mapView.setCenter(CLLocationCoordinate2D(latitude: 40.7326808, longitude: -73.9843407), zoomLevel: 12, animated: false)
view.addSubview(mapView)
// Set the delegate property of our map view to `self` after instantiating it.
mapView.delegate = self
// Declare the marker `hello` and set its coordinates, title, and subtitle.
let hello = MGLPointAnnotation()
hello.coordinate = CLLocationCoordinate2D(latitude: 40.7326808, longitude: -73.9843407)
hello.title = "Hello world!"
hello.subtitle = "Welcome to my marker"
// Add marker `hello` to the map.
mapView.addAnnotation(hello)
}
// Use the default marker. See also: our view annotation or custom marker examples.
func mapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? {
return nil
}
// Allow callout view to appear when an annotation is tapped.
func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
return true
}
}
以下是我希望我的预期输出大致看起来的样子
解决方案
如果您想使用内置的 Mapbox 标注,您可能需要考虑实现-mapView:rightCalloutAccessoryViewForAnnotation:
允许您进一步自定义 MGLCallout 的委托方法,如下例所示:https ://www.mapbox.com/ios-sdk/maps/示例/默认标注/。该委托方法返回一个 UIView,因此您可以自定义 UIView,但是您希望包含所需的按钮。
您会注意到在示例中-mapView:annotation:calloutAccessoryControlTapped:
还实现了另一个委托方法。This gets called when the right callout accessory view (returned by -mapView:rightCalloutAccessoryViewForAnnotation:
) is selected, so you could adapt this by placing your logic in that delegate method when a user selects the right side of the callout view.
推荐阅读
- layout - 如何使用 Flutter 创建具有固定页脚的滚动视图?
- debugging - 如何捕获 x86 CPU 重置的原因?
- c# - NEST (C#) 如何隐式转换类型?
- css - 调整浏览器窗口大小时,引导列重叠
- visual-studio - 使用 MSBuild 的公共 MVC 项目未复制 global.asax 文件,我收到错误 404
- javascript - Marketo“Flyout”动画标签
- scala - 如何为流任务的日志成员设置 SBT logLevel?
- android - How to synchronize GraphQL changes from Appsync to Android using amplify?
- javascript - Nuxt:显示静态文件夹中的本地图像
- ajax - 加载资源失败:服务器在尝试通过 Selenium 和 Python 登录 Instagram 时响应状态为 400 ()