8
以下是我希望獲得類似風格的示例自定義標註。我正在考慮從MKAnnotation繼承,但我失去了如何啓動它,我不知道標註的設計是否可以被覆蓋。iOS Mapkit自定義標註
任何想法如何實現與內部UI控件這個自定義標註?
編輯:下面是來自以下類似StackOverflow的答案我的代碼:
- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if(annotationView)
return annotationView;
else
{
UIImage *img = [UIImage imageNamed:@"default_thumb.png"];
MKAnnotationView *annotationView =
[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
annotationView.canShowCallout = YES;
annotationView.image = img;
annotationView.draggable = YES;
/*
// change left accessory view button with image
UIImageView *leftAccView = [[UIImageView alloc] initWithImage:img];
annotationView.leftCalloutAccessoryView = leftAccView;
//include a right button to show more info
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:@selector(calloutSubMenu:) forControlEvents:UIControlEventTouchUpInside];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
annotationView.rightCalloutAccessoryView = rightButton;
*/
return annotationView;
}
return nil;
}
// Customize accessory view
- (void)mapView:(MKMapView *)mapview annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
[mapview deselectAnnotation:view.annotation animated:YES];
PopOverCallout *popOverCallout = [[PopOverCallout alloc]init];
UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:popOverCallout];
self.annotationPopoverController = popOver;
popOver.popoverContentSize = CGSizeMake(500, 500);
[popOver presentPopoverFromRect:view.bounds inView:view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
每當引腳被觸摸,顯示標註正確的
(void)mapView:(MKMapView *)mapview annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
應該叫什麼名字?但是會發生什麼情況是顯示空白的常規標註。我可能會做錯什麼?
順便說一句:UIViewController子類只有XIB上的標籤,並且非常空白。
請參閱[此類似的問題](http://stackoverflow.com/questions/5582564/how-do-i-display-a-uipopoverview-as-a-annotation-to-the-map-view-ipad/ 5583505#5583505)。 – Anna
謝謝。我想這是一個確切的副本。我可能會刪除這個問題,如果其他職位的解決方案是我正在尋找。 – Bahamut
@Anna Karenina - 你能告訴我爲什麼它仍然顯示一個常規的標註嗎?我添加了我的代碼 – Bahamut