如何仅对新删除的注释进行动画处理?

How to only animate newly dropped Annotations?

我有一个应用程序,允许用户在一个视图中 select 大学,在他们 selected 之后,该视图消失并出现一张地图。目前,我正在使用下面的代码,但它为所有注释设置了动画。我希望现有注释不动画化,只在视图关闭时动画化新 selected 学院。

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
    let reuseID = "pin"

    var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseID) as? MKPinAnnotationView

    if pinView == nil {
        pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseID)
        pinView?.canShowCallout = true
        pinView?.rightCalloutAccessoryView = UIButton(type: .DetailDisclosure)
        pinView?.animatesDrop = true
    } else {
        pinView?.annotation = annotation
        pinView?.animatesDrop = true
    }
    return pinView
}

您可以创建自定义注释并为其添加一个布尔值,以检查之前是否添加过它。

class CustomPointAnnotation: MKPointAnnotation {
    var name: String!
    var exists: Bool!
}

然后在添加注释时使用 CustomPointAnnotation 并检查 exists 是否为 true 然后你不设置动画,如果 false 然后设置动画。