【问题标题】:Creating buttons for a popup(Speech Bubble) in Mapbox using Swift使用 Swift 在 Mapbox 中为弹出窗口(语音气泡)创建按钮
【发布时间】:2018-10-06 03:27:38
【问题描述】:

我用相同的代码发布了另一个问题,但这个问题不同。

我想在显示的语音气泡的右下角添加按钮

Hello World! 
Welcome to my marker!

我想知道如何在此处放置按钮,但如果您想知道按钮的作用,其中一个会跟踪气泡获得的其他用户有多少赞成票,另一个会发送请求给另一个用户。

另外,我发现 this example 看起来像是实现了一个不同版本的语音气泡(弹出窗口),可能更好用

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
    }
}

以下是我希望我的预期输出大致看起来的样子

【问题讨论】:

  • 您想自定义地图注释视图还是其他任何内容?您能否添加您预期结果的屏幕截图。
  • @NikunjKumbhani 我添加了我的预期输出应该是什么样子。有一个赞成按钮,一个消息按钮,然后是一个查看个人资料按钮。我主要是想知道如何将按钮放入语音气球,然后如何让它们访问某些请求。

标签: ios iphone swift mapbox


【解决方案1】:

如果您想使用内置 Mapbox 标注,您可能需要考虑实现 -mapView:rightCalloutAccessoryViewForAnnotation: 委托方法,该方法允许您进一步自定义 MGLCallout,如下例所示:https://www.mapbox.com/ios-sdk/maps/examples/default-callout/。该委托方法返回一个 UIView,因此您可以 customize the 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.

【讨论】:

猜你喜欢
  • 2022-10-01
  • 1970-01-01
  • 2014-04-23
  • 1970-01-01
  • 2016-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多