Bil*_*ver 10 objective-c mkpinannotationview mkmapview ios
我在MapView上显示用户头像图像.如果在没有动画的情况下渲染它们,它们似乎正在工作,但是我想为它们的动画制作动画.如果我将pinView.animatesDrop设置为true,那么我将丢失头像并将其替换为pin.如何在不使用针的情况下为我的头像添加动画效果?
这是我正在使用的viewForAnnotation方法:
- (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;
}
Run Code Online (Sandbox Code Playgroud)
小智 35
当您想要将自己的图像用于注释视图时,最好创建一个常规图像MKAnnotationView而不是一个MKPinAnnotationView.
由于它MKPinAnnotationView是一个子类MKAnnotationView,它有一个image属性,但它通常(通常当你不指望它)忽略它并改为显示其内置的pin图像.
因此,不要与它斗争,最好只使用平原MKAnnotationView.
不使用的最大问题MKPinAnnotationView是你必须手动实现的内置掉落动画.
有关更多详细信息,请参阅此前一个答案:
MKMapView:自定义视图而不是注释引脚
| 归档时间: |
|
| 查看次数: |
16780 次 |
| 最近记录: |