程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ios-MKAnnotation顯示問題

ios-MKAnnotation顯示問題

編輯:編程綜合問答
MKAnnotation顯示問題

MKMapView 中有一個標志針
點擊標記針時可以看見標題和副標題,怎麼樣不需要點擊標記讓標題自動顯示。
代碼如下:

 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;

}

最佳回答:


使用MKMapViewselectAnnotation:animated 方法

[mapView selectAnnotation:YorAnnotation animated:YES];
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved