【发布时间】:2016-06-10 13:02:37
【问题描述】:
我是 iOS 开发和 mapbox 的新手,如果问题听起来很愚蠢,我很抱歉,但我在任何地方都找不到答案。 我有一张地图和注释。当用户触摸并按住注释(长按手势)时,我想显示一些其他信息。我得到了长按手势来工作,但是找到了找到被触摸的注释的方法,或者至少是它的索引。到目前为止,我是这样的:
class eventsMapController: UIViewController, MGLMapViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
mapView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
// Set the map's bounds to Oslo 59.920269,10.71167
//let bounds = MGLCoordinateBounds(sw: CLLocationCoordinate2D(latitude: 59.925861, longitude: 10.712185),
// ne: CLLocationCoordinate2D(latitude: 59.889798, longitude: 10.794754))
view.addSubview(mapView)
// Set the map view‘s delegate property
mapView.delegate = self
let myGesture = UILongPressGestureRecognizer(target: self, action: #selector(eventsMapController.testLongGesture))
myGesture.minimumPressDuration = 0.8
mapView.addGestureRecognizer(myGesture)
}
func testLongGesture(long: UILongPressGestureRecognizer){
if long.state == .Began{
print("begin", long)
}
}
}
我正在添加这样的注释
let pointAnotation = MGLPointAnnotation()
pointAnotation.coordinate = CLLocationCoordinate2DMake(event.lat, event.lng)
pointAnotation.title = name
pointAnotation.subtitle = headline
self.mapView.addAnnotation(pointAnotation)
请帮帮我,我花了好几个小时才弄明白。
【问题讨论】:
标签: ios swift annotations mapbox