2014-09-04 61 views
2

我在我的應用程序中顯示一些地圖,該地圖顯示我自己的項目的一些POI。我沒有使用默認的紅色針腳,但決定自己做一個。這個引腳工作,看起來很好,當我點擊它時,我得到了標註泡泡,但它沒有顯示右側的默認附件按鈕。但是,它確實顯示空的空間,表明它在那裏,如果我從右向左改變它,它確實會移動,但我看不到它。顯示標註附件按鈕,但不可見

The whitespace is where the button is normally

正如你可以看到我的泡沫顯然騰出按鈕,當我點擊此按鈕的應該是它會實際運行我

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { 

沒有因此出現任何問題配件按鈕只是'隱藏'。

這是我對默認的註釋視圖代碼:

- (MKAnnotationView *)annotationView { 
MKAnnotationView *annotationView = [[MKAnnotationView alloc] initWithAnnotation:self reuseIdentifier:@"PlaceAnnotation"]; 

annotationView.enabled = YES; 
annotationView.canShowCallout = YES; 
annotationView.image = [UIImage imageNamed:@"annotationPin"]; 
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
annotationView.centerOffset = CGPointMake(0, -annotationView.image.size.height/2); 

return annotationView; 

}

這是我的MapViewController本身代碼:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { 
if ([annotation isKindOfClass:[PlaceAnnotation class]]) { 

    PlaceAnnotation *placeAnnotation = (PlaceAnnotation *)annotation; 

    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"PlaceAnnotation"]; 

    if (annotationView == nil) { 
     annotationView = placeAnnotation.annotationView; 
    } else { 
     annotationView.annotation = annotation; 
    } 

    return annotationView; 
} else { 
    return nil; 
} 

}

我錯了,以爲

.rightCalloutAccessoryView = ... 

是我需要使按鈕顯示的唯一行嗎?我只想在我的文本旁邊有一個默認的藍色圓圈,所以我的用戶很清楚他們可以點擊泡泡。

S.

+1

你是否在應用程序中的任何位置設置了tintColor(就像UIButton的外觀一樣)? – Anna 2014-09-04 17:50:26

+0

我的代碼中沒有提到tintColor。然而,你的評論讓我想知道如果我可以將我的annotationView的tintColor更改爲藍色,以查看tintColor是否確實導致了問題(並且因爲我只將它應用於我的annotationView,它不會影響其他任何內容),並且猜怎麼着......問題解決了!請重新撰寫您的評論作爲答案,以便我可以接受。 – Rijstkoek 2014-09-04 21:17:02

回答

1

它爲什麼你的附件按鈕是「看不見」的,但標準UIButton S被tintColor設置的影響目前尚不清楚。

嘗試在註解視圖明確設置tintColor

annotationView.tintColor = [UIColor blueColor]; 
0

該tintColor沒有一些上場後爲我工作,所以身邊我得到這個工作。

訣竅是爲圖像設置一個框架。詳細公開按鈕的工作原理是因爲它已經設置了大小:

UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [infoButton setImage:[UIImage imageNamed:@"directionArrow.png"] forState:UIControlStateNormal]; 
    [infoButton setFrame:CGRectMake(0,0,30,30)]; 
    pinAnnotation.rightCalloutAccessoryView = infoButton;