MKPinAnnotationView 不动

发布于 2024-11-30 22:47:04 字数 1838 浏览 2 评论 0原文

我在这里浏览了一些链接,但不是全部,关于 MKPinAnnotationView 引脚、子类等。我在网上做了一些简单的教程,当我认为我可以用来自教程,我错了。 :(

在我的教程文件中,我设法做了一个简单的 MKPinAnnotationView *pin。设置其属性,例如 canShowCallOut = YESdraggable = YES。我可以将 pin 拖动到任何地方我想显示它掉落的位置,

但是当我创建新应用程序时,我又做了同样的事情,但是图钉没有移动,我做错了什么吗?

    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{

    if([annotation isKindOfClass:[CustomPlacemark class]])
    {
        MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:[annotation title]];
        newAnnotation.pinColor = MKPinAnnotationColorGreen;
        newAnnotation.animatesDrop = YES; 
        newAnnotation.canShowCallout = YES; // shows the black label when the pin is tapped
        newAnnotation.draggable = YES;
//      newAnnotation.enabled = YES;
        newAnnotation.tag = tag;
        NSLog(@"%@ %@", [annotation title], [annotation subtitle]);
        UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [rightButton addTarget:self
                        action:@selector(showDetails:)
              forControlEvents:UIControlEventTouchUpInside];
        newAnnotation.rightCalloutAccessoryView = rightButton;

        NSLog(@"Created annotation at: %f %f", ((CustomPlacemark*)annotation).coordinate.latitude, ((CustomPlacemark*)annotation).coordinate.longitude);

        [newAnnotation addObserver:self
                        forKeyPath:@"selected"
                           options:NSKeyValueObservingOptionNew
                           context:@"GMAP_ANNOTATION_SELECTED"];

        [newAnnotation autorelease];
        tag++;
        NSLog(@"ååååååååå %@", appDelegate.fml);
        return newAnnotation;
    }

    return nil;
}

I have went through a few links here, not all of them, regarding MKPinAnnotationView pin, subclass, etc. I did some simple tutorials online and when I thought I could start on my application with the knowledge from the tutorials, I was wrong. :(

In my tutorial file, I managed to do a simple MKPinAnnotationView *pin. Set its properties, like canShowCallOut = YES, draggable = YES. I can drag the pin anywhere I want to and display the location its dropped at.

But when I created my new application, I did the same thing again. But the pin isn't moving, is there something I did wrong?

    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{

    if([annotation isKindOfClass:[CustomPlacemark class]])
    {
        MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:[annotation title]];
        newAnnotation.pinColor = MKPinAnnotationColorGreen;
        newAnnotation.animatesDrop = YES; 
        newAnnotation.canShowCallout = YES; // shows the black label when the pin is tapped
        newAnnotation.draggable = YES;
//      newAnnotation.enabled = YES;
        newAnnotation.tag = tag;
        NSLog(@"%@ %@", [annotation title], [annotation subtitle]);
        UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [rightButton addTarget:self
                        action:@selector(showDetails:)
              forControlEvents:UIControlEventTouchUpInside];
        newAnnotation.rightCalloutAccessoryView = rightButton;

        NSLog(@"Created annotation at: %f %f", ((CustomPlacemark*)annotation).coordinate.latitude, ((CustomPlacemark*)annotation).coordinate.longitude);

        [newAnnotation addObserver:self
                        forKeyPath:@"selected"
                           options:NSKeyValueObservingOptionNew
                           context:@"GMAP_ANNOTATION_SELECTED"];

        [newAnnotation autorelease];
        tag++;
        NSLog(@"ååååååååå %@", appDelegate.fml);
        return newAnnotation;
    }

    return nil;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文