2016-09-27 53 views
0

对于swift编程来说我相当新,我想用一个MKMapview制作一个应用程序,该应用程序包含多个带有按钮的缩进到其他UIViewControrrs的注释。是否有可能为我创建一个像通常使用常规UIButton一样的操作?如果没有,我如何继续对其他UIViewControllers?如何在swift中为地图注释按钮制作一个动作

+0

你就不能添加目标到去一个按钮功能?或者同样将按钮连接到IBAction?我之前没有使用MKMapview,但我无法想象它会有很大的不同 –

回答

0

你需要做一个自定义注释视图:

func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! { 
    // add here a button 
    var button = UIButton.buttonWithType(.DetailDisclosure) as UIButton // button with info sign 
    yourView.rightCalloutAccessoryView = button 
} 

再检查时,按下按钮:

func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!) { 
    if control == view.rightCalloutAccessoryView{ 
     print(view.annotation.title) // your annotation's title 
     //Perform a segue here to navigate to another viewcontroller 
     self.performSegueWithIdentifiert("yourSegue") 
    } 
}