简体   繁体   English

MKMapView上的图钉注释上的触摸事件

[英]Touch event on an pin annotation on a MKMapView

i've been trying to display a view controller when I tap on a pin annotation of my map View: The first time I used a container view and change his position in order to "hide" it. 当我点击地图视图的图钉注释时,我一直试图显示视图控制器:第一次使用容器视图并更改其位置以“隐藏”它。 Than, when I tap on an annotation I used the func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView){} to move the position of the view controller that I want to display to the center of my screen. 然后,当我点击注释时,我使用了func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView){}将要显示的视图控制器的位置移动到屏幕中心。 Unfortunately I wasn't able to close the view controller because when I tried to use the function dismissViewController .... It dismiss all the view controllers of my app. 不幸的是,我无法关闭视图控制器,因为当我尝试使用函数dismissViewController ....时,它将关闭我应用程序的所有视图控制器。 So I trie to move the position of the view controller that I want to display a when the user touch the close button, it works only one time, if I tap on an other annotation, the view controller won't show up. 因此,我尝试移动要显示的视图控制器的位置,当用户触摸关闭按钮时,它只能运行一次,如果我点击其他注释,则视图控制器将不会显示。 I can't do with segue because the annotation aren't shown in the main.storyboard To resume, my question is: How can I display a second View Controller by touching an annotation on my map. 我无法使用segue,因为在main.storyboard中未显示注释。要恢复,我的问题是:如何通过触摸地图上的注释来显示第二个View Controller。

I tried the function performseguewithidentifier on following method: 我在以下方法上尝试了功能performseguewithidentifier

func mapView(mapView: MKMapView, didSelectAnnotationView view:  MKAnnotationView){
    // do your things here
} 

and it worked fine. 而且效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM