简体   繁体   English

MKAnnotation image属性的问题

[英]issue with with MKAnnotation image property

I am implementing a MKMapView based application. 我正在实现一个基于MKMapView的应用程序。 In that I am using a custom image instead of displaying a pin by using MKAnnotationView.Image property. 在这种情况下,我使用自定义图像,而不是通过使用MKAnnotationView.Image属性来显示图钉。 It is not working. 它不起作用。 It keeps showing the standard pin in red but not the image I am pointing too. 它始终以红色显示标准图钉,但也没有显示我指向的图像。 Any ideas? 有任何想法吗?

- (void)setPin:(MKPinAnnotationView *)aPin forAnnotation:(id <MKAnnotation>)anAnnotation {
    if (anAnnotation == self.userAnnotation) {

        aPin.image = [UIImage imageNamed:@"youarehere.png"];
        aPin.opaque = NO;

        aPin.pinColor = MKPinAnnotationColorRed;
    }
}

If you use MKPinAnnotationView like you are then you don't get to set the image only the pinColor. 如果像您一样使用MKPinAnnotationView ,那么您将无法仅将图像设置为pinColor。 MKPinAnnotationView only has pinColor and animatesDrop as the properties. MKPinAnnotationView只有pinColoranimatesDrop的性能。

You want to use the parent class MKAnnotationView . 您想使用父类MKAnnotationView It will let you set the image. 它可以让您设置图像。

Read the Class Reference for each and it will make sense. 阅读每个类的类参考,它将很有意义。 This is one of the times that Objective-C makes me crazy because when you are reading those long class names in the docs, it's easy to scan right over the "Pin" variation in the class name. 这是Objective-C令我发疯的时候之一,因为当您在文档中阅读那些冗长的类名时,可以很容易地在类名的“ Pin”变体中进行扫描。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM