iphone - 显示问题的MKA注释

标签 iphone ios objective-c mkmapview mapkit

我创建了MKMapView,上面有一个针脚。

按下图钉时,我会看到标题和副标题,但我想不点击就看到它。
因此,我希望标题和副标题在显示 map 后立即出现。

这是我的代码:

    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;

}

最佳答案

使用MKMapView's selectAnnotation:animated方法

[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)问题。

关于iphone - 显示问题的MKA注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15615201/

相关文章:

iphone - iOS5 @property 变化

iphone - 带有静态库的 iOS 应用程序仅在启动加载 Ad Hoc 的存档构建时崩溃。无法在调试器中重现

ios - 在 Swift 中以编程方式创建 UITextView 时未获得输出

ios - SwiftUI - 限制 View 内矩形的拖动

objective-c - 为什么 Instruments 将此报告为内存泄漏?

php - 使用 NSURLRequest 通过 POST 将键值对传递给 PHP 脚本

iphone - View Controller 之间的自定义转换?

ios - NSURLConnection 在重新启动应用程序后总是失败

iphone - 键盘、方向和 UITextView

iphone - iOS TableView 钻取卡住