我在 UIView 子类中有一个 MKMapView 实例,它通过实现 viewForAnnotation:(id<MKAnnotation>) annotation
符合 MKMapViewDelegate 协议(protocol)。方法。其代码为:
- (MKAnnotationView*) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
if ([annotation isKindOfClass:[DriverLocation class]]) {
MKAnnotationView* a = [self.map dequeueReusableAnnotationViewWithIdentifier:@"driverView"];
if (a == nil) {
MKAnnotationView* a = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"driverView"];
a.enabled = YES;
a.image = [UIImage imageNamed:@"car.png"];
}
return a;
}
return nil;
图像未正确加载 - 加载的图像属性的高度和宽度为零,MKAnnotationView 实例 a 的尺寸也为零。
图像是 4Kb png 32 像素 x 32 像素。
我可以确认图像已被复制到模拟器的根 .app 目录中。
如果您能提供有关为何未加载的任何帮助,我们将不胜感激!
最佳答案
为了这篇文章的完整性:你需要改变
MKAnnotationView* a = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"driverView"];
到:
a = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"driverView"];
关于iphone - MKAnnotationView 图像不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9439987/