I have created a custom MKAnnotation class and it has been working - until iOS 6 came out. Since then my pins get added to the apple map but now without a drop animation! Is this how it is set or there maybe an an issue with the way I'm doing things. I have set a delay of 1 sec until the method that adds the annotations to the map is called, so I can see if the drop animations are actually occurring before the view appears - still, the pins just appear out of nowhere without dropping. Here's the code I'm using:
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(Annotation*)annotation
{
NSLog(@"the annotation ID is: %@", annotation.ID);
MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"];
UIButton *goToObjectButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[goToObjectButton addTarget:self action:@selector(goToObjectClick:) forControlEvents:UIControlEventTouchUpInside];
MyPin.pinColor = MKPinAnnotationColorRed;
MyPin.rightCalloutAccessoryView = goToObjectButton;
MyPin.draggable = NO;
MyPin.highlighted = YES;
MyPin.animatesDrop=YES;
MyPin.canShowCallout = YES;
return MyPin;
}
It appears that with the new Apple MapKit in iOS 6, the sequence of when annotations are added onto a MKMapView has changed a bit.
(In my own case, I used to add annotations, then set the delegate of the map view immediately after, and before iOS 6, the annotations didn't appear until later in the run cycle, but now they try to add immediately.)
So, it may be an issue that either the annotations are being added before the delegate is hooked up, or that you're adding the annotations too early and just not seeing the animation. More code samples regarding when the MKMapView is being created (assuming you're doing it in code, and not in a .xib) and when you're adding your annotations might help clarify what's wrong.
I have found also that in iOS6 the sequence/timing of what is displayed on the MKMapView has changed. I used to add my annotations to the map in viewDidLoad which worked fine in iOS5, but with iOS6 the pins do not drop they just appear. I've now moved the code to viewDidAppear and the pins now animate the drop from above. However they all drop at once, not individually as they did in iOS5.
MkMappin Dropdown Bounce Animation Works - Prem Kumar(iOS Developer)
-(void)addPinWithTitle:(NSString *)title AndCoordinate:(NSString *)strCoordinate
{
MKPointAnnotation *mapPin = [[MKPointAnnotation alloc] init];
// clear out any white space
strCoordinate = [strCoordinate stringByReplacingOccurrencesOfString:@" " withString:@""];
// convert string into actual latitude and longitude values
NSArray *components = [strCoordinate componentsSeparatedByString:@","];
double latitude = [components[0] doubleValue];
double longitude = [components[1] doubleValue];
// setup the map pin with all data and add to map view
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
mapPin.title = [title valueForKey:@"restaurantBranchName"];
mapPin.coordinate = coordinate;
[locationMapView addAnnotation:mapPin];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKAnnotationView *annotationView = [locationMapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if(annotationView)
return annotationView;
else
{
MKAnnotationView *annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:AnnotationIdentifier];
annotationView.canShowCallout = YES;
UIImage *img = [UIImage imageNamed:@"orange_restaurant"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:img];
imageView.frame=CGRectMake(0, 0, 40, 40);
imageView.contentMode=UIViewContentModeScaleAspectFit;
imageView.center = annotationView.center;
[annotationView addSubview:imageView];
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
annotationView.rightCalloutAccessoryView = rightButton;
UIView *rightView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
rightView.backgroundColor=ThemeColor;
rightView.layer.cornerRadius=rightView.frame.size.width/2;
annotationView.leftCalloutAccessoryView=rightView;
annotationView.canShowCallout = YES;
annotationView.draggable = YES;
return annotationView;
}
return nil;
}
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
MKAnnotationView *aV;
for (aV in views) {
// Don't pin drop if annotation is user location
if ([aV.annotation isKindOfClass:[MKUserLocation class]]) {
continue;
}
// Check if current annotation is inside visible map rect, else go to next one
MKMapPoint point = MKMapPointForCoordinate(aV.annotation.coordinate);
if (!MKMapRectContainsPoint(mapView.visibleMapRect, point)) {
continue;
}
CGRect endFrame = aV.frame;
aV.frame = CGRectMake(aV.frame.origin.x, aV.frame.origin.y - self.view.frame.size.height, aV.frame.size.width, aV.frame.size.height);
[UIView animateWithDuration:0.5 delay:0.04*[views indexOfObject:aV] options: UIViewAnimationOptionCurveLinear animations:^{
aV.frame = endFrame;
}completion:^(BOOL finished){
if (finished) {
[UIView animateWithDuration:0.5 animations:^{
aV.frame = CGRectMake(aV.frame.origin.x, aV.frame.origin.y - self.view.frame.size.height/6, aV.frame.size.width, aV.frame.size.height);
}completion:^(BOOL finished){
if (finished) {
[UIView animateWithDuration:0.5 animations:^{
aV.frame = endFrame;
}];
}
}];
}
}];
}
}