MKAnnotationView无法检测是否触摸了按钮或标题

时间:2015-12-26 21:37:04

标签: mapkit mkannotationview

你好我的问题是这段代码:

<div data-role="page" id="page1" style="background: none;">
  <div id='main-contents'>
    <div id='navigation-drawer'>
      <ul id="list">
        <li class="menuItem" id="helpBtn">
          <p>Help</p>
        </li>
      </ul>
    </div>
  </div>

似乎无法正常工作。问题是,即使我触摸标题而不是按钮,也会始终调用func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) { if control is UIButton { if (control as! UIButton).buttonType == .DetailDisclosure{removeAnnotation()} else{performSegueWithIdentifier("edit", sender: nil)} } } 。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

中添加信息右键
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { 

        // add button here, i.e. 

        let btn = UIButton(type: .Custom)
            btn.frame = CGRectMake(0, 0, 30, 30)
            btn.setImage(UIImage(named: "info"), forState: .Normal)
            annotationView.rightCalloutAccessoryView = btn

        // ... other required code
}

然后在

func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {

    if control == view.rightCalloutAccessoryView {
        print("Tap")
    }
}