如果我们想要把大头针在地图上显示出来,我们想做动画的话,一般来说都是在下面这个代理方法中做的,这个方法会在添加大头针的时候会去调用,并且在会在大头针出现之前。
-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray<MKAnnotationView *> *)views
在调用这个方法前会去调用下面这个方法,返回大头针view
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
就比如说我们可以去做一个大头针从天而降的动画效果可以这么做,这里面需要注意的就是,我们这里要判断这个位置是否是用户定位的位置。
-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray<MKAnnotationView *> *)views
{
for(MKAnnotationView * annotationView in views)
{
//首先要去判断,这个大头针是不是用户位置的那个大头针
if([annotationView.annotation isKindOfClass:[MKUserLocation class]])
{
continue;
}
//获取本来应该在的位置
CGRect endFrame = annotationView.frame;
annotationView.frame = CGRectMake(endFrame.origin.x, 0, endFrame.size.width, endFrame.size.height);
[UIView animateWithDuration:10 animations:^{
annotationView.frame = endFrame;
}];
}
}