简体   繁体   English

MKAnnotation显示问题

[英]MKAnnotation showing issues

I created MKMapView with a pin on it. 我用它上面的针创建了MKMapView。

When I press a pin, I see the title and subtitle, but I want to see it without tapping. 当我按下一个引脚时,我会看到标题和副标题,但我希望看到它而不需要点击。 So, I want title and subtitle to appear immediately after showing of map. 所以,我希望在显示地图后立即出现标题和副标题。

Here is my code: 这是我的代码:

    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;

}

Use MKMapView's selectAnnotation:animated method 使用MKMapView's selectAnnotation:animated方法

[mapView selectAnnotation:YorAnnotation animated:YES];

For More info read How to trigger MKAnnotationView's callout view without touching the pin? 有关详细信息,请参阅如何在不触及引脚的情况下触发MKAnnotationView的标注视图? and How to Automatically Display Title/Subtitle on Map Annotation (pin) Question. 以及如何在地图注释(引脚)问题上自动显示标题/副标题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM