首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MKAnnotation显示问题

MKAnnotation显示问题
EN

Stack Overflow用户
提问于 2013-03-25 20:39:16
回答 1查看 122关注 0票数 1

我用大头针创建了MKMapView。

当我按下一个大头针时,我会看到标题和副标题,但我不想点击就能看到它。所以,我希望标题和副标题在地图显示后立即出现。

下面是我的代码:

代码语言:javascript
复制
    self.mapView = [[[MKMapView alloc]init] autorelease];
    mapView.frame = self.view.bounds;
    mapView.delegate = self;
    [self.view addSubview:mapView];

    location = CLLocationCoordinate2DMake(lattitude, longitude);



    MKCoordinateRegion region = self.mapView.region;
    region.center = location;
    region.span.longitudeDelta = kSpan;
    region.span.latitudeDelta = kSpan;
    [self.mapView setRegion:region animated:YES];

    CustomMapAnnotation *newAnnotation = [[CustomMapAnnotation alloc] init];
    newAnnotation.title = @"Title";
    newAnnotation.subtitle = @"Subtitle";
    newAnnotation.accessibilityTraits = UIAccessibilityTraitButton;

    newAnnotation.coordinate = location;
    annotation = newAnnotation;
    [mapView addAnnotation:annotation];
    [newAnnotation release];

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

    MKPinAnnotationView *pinView = nil;

    static NSString *defaultPinID = @"mapPin";

    pinView = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];

    if (pinView == nil)
        pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotationDel reuseIdentifier:defaultPinID] autorelease];

    pinView.pinColor = MKPinAnnotationColorRed;
    pinView.canShowCallout = YES;
    pinView.animatesDrop = YES;
    [pinView setSelected:YES];

    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton addTarget:self action:@selector(detailButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    pinView.rightCalloutAccessoryView = rightButton;

    return pinView;

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-25 20:43:45

使用MKMapView's selectAnnotation:animated方法

代码语言:javascript
复制
[mapView selectAnnotation:YorAnnotation animated:YES];

有关更多信息,请阅读How to trigger MKAnnotationView's callout view without touching the pin?How to Automatically Display Title/Subtitle on Map Annotation (pin)问题。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15615201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档