jef*_*eff 6 annotations objective-c mapkit ios
我试图用特定的图像替换典型的iOS mapkit"pin".我是编码的新手,所以我不确定为什么这不起作用,但这是我尝试过的:
对于该方法
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
Run Code Online (Sandbox Code Playgroud)
除此之外,我还有:
pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
//pinView.pinColor=MKPinAnnotationColorPurple;
UIImage *pinImage = [UIImage imageNamed:@"Jeff.png"];
[pinView setImage:pinImage];
Run Code Online (Sandbox Code Playgroud)
但是,即使代码编译得很好,pinView也没有设置pinImage.任何想法为什么不呢?
小智 3
您所要做的就是将最后一行更改为:
[pinView addSubview:pinImage];
Run Code Online (Sandbox Code Playgroud)
完整示例:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"ParkingPin"];
UIImageView *imageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pin_parking.png"]] autorelease];
annView.animatesDrop = TRUE;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
[annView addSubview:imageView];
return annView;
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
| 归档时间: |
|
| 查看次数: |
18631 次 |
| 最近记录: |