iOS MapKit自定义引脚

Bah*_*mut 16 mapkit ios

如何在地图中显示图像而不是图钉.到目前为止,我只能添加引脚..m的示例代码非常有用,因为我还是iOS编程的新手.

Rob*_*bin 53

#pragma mark -
#pragma mark MKMapView delegate
- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;
    static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
    if(annotationView)
        return annotationView;
    else
    {
        MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
                                                                         reuseIdentifier:AnnotationIdentifier] autorelease];
        annotationView.canShowCallout = YES;
        annotationView.image = [UIImage imageNamed:@"someImage.png"];
        UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [rightButton addTarget:self action:@selector(writeSomething:) forControlEvents:UIControlEventTouchUpInside];
        [rightButton setTitle:annotation.title forState:UIControlStateNormal];
        annotationView.rightCalloutAccessoryView = rightButton;
        annotationView.canShowCallout = YES;
        annotationView.draggable = YES;
        return annotationView;
    }
    return nil;
 }
Run Code Online (Sandbox Code Playgroud)

编辑:

我可以向你解释所有这些MKAnnotationView,但我认为你会发现Apple提供的文档比任何其他来源都要好得多.检查链接中的概述部分.

https://developer.apple.com/documentation/mapkit/mkannotationview


jbc*_*iya 6

转到Xcode的组织者,然后转到文档并搜索weatherMap,它显示了地图的示例,其中包含注释中的图像.