的期望的行爲是能夠在標註氣泡的任何地方挖掘和已對其執行在rightCalloutAccessory按鈕的動作。
它是需要的,因爲加入UIControl要麼calloutAccessory使得整個標註泡沫可選(意味着當你點擊它,錯誤地指示給用戶,這應該產生一個動作它突出),但不提供實施者任何方式檢測並響應此抽頭,這導致了令人困惑的用戶體驗。
下面是我解決問題的方法。
當創建MKAnnotationView,一個tapGesture添加到MKAnnotationView
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id<MKAnnotation>)annotation {
MKAnnotationView *aView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotation.reuseID];
aView.canShowCallout = YES;
UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:annotation.callOutImageName]];
aView.leftCalloutAccessoryView = image;
UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[obsDetailButton setImage:[UIImage imageNamed:@"your_image.png"] forState:UIControlStateNormal];
aView.rightCalloutAccessoryView = detailButton;
UITapGestureRecognizer *singleTapOnCallout = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(calloutTapped:)];
[aView addGestureRecognizer:singleTapOnCallout];
}
然後,在回調方法用於姿勢,如果選擇了annotationView檢查,並且如果是這樣,則執行所需的操作
- (void)calloutTapped:(UIGestureRecognizer *)sender {
MKAnnotationView *annotationView = (MKAnnotationView *)sender.view;
if (annotationView.selected) {
//Perform desired action on selection
}
}
現在這不是一個「完美」的解決方案,因爲如果您點擊註釋一次,顯示標註,然後在顯示標註時點擊標註(不是標註),則會執行操作。不過,我認爲這是一個更直觀的體驗,而不是讓您的標註突出顯示而沒有發生任何行動,所以在給出選擇的情況下,我更喜歡這一點。
很明顯,理想的解決方案是讓Apple公開默認的標註視圖並允許您直接爲其添加一個gestureRecognizer。或者甚至更好,因爲它提供了一個委託方法,告訴你插入的標註。
在這種情況發生之前,這是我能想出的最佳解決方案。希望它能幫助別人!
推薦的行爲是添加一個正確的配件視圖,我建議你一開始這樣做。用戶更容易找到他(她)可以點擊的地方。有用。 – 2012-04-02 15:46:46