在 swift 中向 AnnotationPin 添加操作

Add action to an AnnotationPin in swift

我在 swift 上制作了一张 "classic" 地图,其中包含用户位置和一些 AnnotationPin。我使用 iOS 11 的默认外观,所以当我点击 Pin 图时,它会变大。名称和子名称也显示在引脚下方。

我的问题是:如何添加一个动作,以便在我点击 Pin 图时转到另一个页面来显示内容?也许我可以替换这个 "zoom" 在 pin 上或在那里添加我的操作,但我不知道如何(我是初学者)。

谢谢! :)

使用 mapView 的 didSelect 委托方法。

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    performSegue(withIdentifier: "toTheMoon", sender: self)
}

另见 How to perform segue programmatically in Xcode 8 : Swift 3