MKPinAnnotationView自定义图像被带有动画下落的图钉替换 [英] MKPinAnnotationView custom Image is replaced by pin with animating drop
问题描述
我在MapView上显示用户头像图像。如果在没有动画的情况下渲染它们,它们似乎正在工作,但是我想为它们的动画制作动画。如果我将pinView.animatesDrop设置为true,那么我将丢失头像并将其替换为pin。如何在不使用pin的情况下为我的头像设置动画?
I'm displaying user avatar images on a MapView. The avatars appear to be working if they are rendered without animation, however I'd like to animate their drop. If I set pinView.animatesDrop to true, then I lose the avatar and it is replaced by the pin. How can I animate the drop of my avatar without using the pin?
这是我正在使用的viewForAnnotation方法:
Here is my viewForAnnotation method I'm using:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
MKPinAnnotationView* pinView = (MKPinAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier:@"MyAnnotation"];
if (!pinView) {
pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotation"];
}
else
pinView.annotation = annotation;
//If I set this to true, my image is replaced by the pin
//pinView.animatesDrop = true;
//I'm using SDWebImage
[pinView setImageWithURL:[NSURL URLWithString:@"/pathtosomeavatar.png"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
//Adding a nice drop shadow here
pinView.layer.shadowColor = [UIColor blackColor].CGColor;
pinView.layer.shadowOffset = CGSizeMake(0, 1);
pinView.layer.shadowOpacity = 0.5;
pinView.layer.shadowRadius = 3.0;
return pinView;
}
推荐答案
当你想使用你的时候自己的注释视图图像,最好创建一个常规的 MKAnnotationView
而不是 MKPinAnnotationView
。
When you want to use your own image for an annotation view, it's best to create a regular MKAnnotationView
instead of an MKPinAnnotationView
.
由于 MKPinAnnotationView
是 MKAnnotationView
的子类,因此它具有图像
属性,但它通常(通常在您不指望它时)忽略它并改为显示其内置图像。
Since MKPinAnnotationView
is a subclass of MKAnnotationView
, it has an image
property but it generally (usually when you don't expect it) ignores it and displays its built-in pin image instead.
所以不要与它斗争,最好只使用普通的 MKAnnotationView
。
So rather than fighting with it, it's best to just use a plain MKAnnotationView
.
你最重要的事情不使用输入MKPinAnnotationView
是你必须手动实现的内置掉落动画。
The big thing you lose by not using MKPinAnnotationView
is the built-in drop animation which you'll have to implement manually.
参见以前的答案有关详细信息:
MKMapView:而不是注释引脚,自定义视图
See this previous answer for more details:
MKMapView: Instead of Annotation Pin, a custom view
这篇关于MKPinAnnotationView自定义图像被带有动画下落的图钉替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!