@@ -104,47 +104,59 @@ - (id) init {
104104// map annotation drop code from: https://stackoverflow.com/questions/6808876/how-do-i-animate-mkannotationview-drop
105105- (void )mapView : (MKMapView *)mapView didAddAnnotationViews : (NSArray *)views {
106106 MKAnnotationView *aV;
107-
107+
108108 for (aV in views) {
109-
109+
110110 // Don't pin drop if annotation is user location
111111 if ([aV.annotation isKindOfClass: [MKUserLocation class ]]) {
112112 continue ;
113113 } else if ([aV.annotation isKindOfClass: [AreaAnnotation class ]]) {
114114 continue ;
115115 }
116-
116+
117117 // Check if current annotation is inside visible map rect, else go to next one
118118 MKMapPoint point = MKMapPointForCoordinate (aV.annotation .coordinate );
119119 if (!MKMapRectContainsPoint (self.mapView .visibleMapRect , point)) {
120120 continue ;
121121 }
122-
123- CGRect endFrame = aV.frame ;
124-
125- // Move annotation out of view
126- aV. frame = CGRectMake (aV. frame . origin . x , aV. frame . origin . y - mapView. frame . size . height , aV. frame . size . width , aV. frame . size . height );
127-
128- // Animate drop
129- [UIView animateWithDuration: 0.5 delay: 0.04 *[views indexOfObject: aV] options: UIViewAnimationOptionCurveLinear animations: ^{
130-
131- aV. frame = endFrame;
132-
133- // Animate squash
134- } completion: ^( BOOL finished){
135- if (finished) {
136- [UIView animateWithDuration: 0.05 animations: ^{
137- aV. transform = CGAffineTransformMakeScale ( 1.0 , 0.8 );
122+
123+ if ([ aV.annotation isKindOfClass: [ObservationAnnotation class ]]) {
124+ ObservationAnnotation *obsAnn = (ObservationAnnotation *)aV. annotation ;
125+
126+ if (obsAnn. selected ) {
127+ dispatch_async ( dispatch_get_main_queue (), ^{
128+ [mapView selectAnnotation: obsAnn animated: NO ];
129+ });
130+ } else {
131+ CGRect endFrame = aV. frame ;
132+
133+ // Move annotation out of view
134+ aV. frame = CGRectMake (aV. frame . origin . x , aV. frame . origin . y - mapView. frame . size . height , aV. frame . size . width , aV. frame . size . height );
135+
136+ // Animate drop
137+ [UIView animateWithDuration: 0.5 delay: 0.04 *[views indexOfObject: aV] options: UIViewAnimationOptionCurveLinear animations: ^{
138138
139+ aV.frame = endFrame;
140+
141+ // Animate squash
139142 }completion: ^(BOOL finished){
140143 if (finished) {
141- [UIView animateWithDuration: 0.1 animations: ^{
142- aV.transform = CGAffineTransformIdentity;
144+ [UIView animateWithDuration: 0.05 animations: ^{
145+ aV.transform = CGAffineTransformMakeScale (1.0 , 0.8 );
146+
147+ }completion: ^(BOOL finished){
148+ if (finished) {
149+ [UIView animateWithDuration: 0.1 animations: ^{
150+ aV.transform = CGAffineTransformIdentity;
151+
152+ }];
153+ }
143154 }];
144155 }
145156 }];
146157 }
147- }];
158+ return ;
159+ }
148160 }
149161}
150162
@@ -941,14 +953,10 @@ - (MKAnnotationView *)mapView:(MKMapView *) mapView viewForAnnotation:(id <MKAnn
941953 } else if ([annotation isKindOfClass: [ObservationAnnotation class ]]) {
942954 ObservationAnnotation *observationAnnotation = annotation;
943955 MKAnnotationView *annotationView = [observationAnnotation viewForAnnotationOnMapView: self .mapView];
944- annotationView.layer .zPosition = [observationAnnotation.observation.timestamp timeIntervalSinceReferenceDate ];
945956 annotationView.canShowCallout = self.canShowObservationCallout ;
946957 annotationView.hidden = self.hideObservations ;
947958 annotationView.accessibilityElementsHidden = self.hideObservations ;
948959 annotationView.enabled = !self.hideObservations ;
949- if (self.previewDelegate ) {
950- [self .previewDelegate registerForPreviewingWithDelegate: self .previewDelegate sourceView: annotationView];
951- }
952960 return annotationView;
953961 } else if ([annotation isKindOfClass: [GPSLocationAnnotation class ]]) {
954962 GPSLocationAnnotation *gpsAnnotation = annotation;
@@ -967,7 +975,6 @@ - (MKAnnotationView *)mapView:(MKMapView *) mapView viewForAnnotation:(id <MKAnn
967975 return pinView;
968976 }
969977
970-
971978 return nil ;
972979}
973980
0 commit comments