【问题标题】:Callout accessory button displayed, but invisible标注附件按钮已显示,但不可见
【发布时间】:2014-09-04 17:13:45
【问题描述】:

我的应用中有一张地图,其中显示了我自己项目的一些兴趣点。我没有使用默认的红色别针,但决定自己制作一个。此图钉工作正常,看起来很好,当我点击它时,我会看到标注气泡,但它没有在右侧显示默认的附件按钮。但是,它确实显示空白区域,表明它在那里,如果我将它从右向左更改,它确实会移动,但我看不到它。

正如你所看到的,我的气泡显然为按钮腾出了空间,当我点击按钮应该在的位置时,它实际上会运行我的

- (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 = ...

是我需要使按钮显示的唯一行吗?我只想要默认的蓝色圆圈,在我的文本旁边中间有一个 i,这样我的用户就可以清楚地知道他们可以点击气泡。

S.

【问题讨论】:

  • 您是否在应用程序的任何位置设置了 tintColor(如 UIButton 外观)?
  • 我的代码中没有提及 tintColor。但是,您的评论让我想知道是否可以将我的 annotationView 的 tintColor 更改为蓝色,以查看 tintColor 是否确实导致了问题(因为我只将它应用于我的 annotationView 它不会影响其他任何东西)和你猜怎么着...问题解决了!请重新写下您的评论作为答案,以便我接受。

标签: ios mkmapview


【解决方案1】:

尚不清楚为什么您的附件按钮“不可见”,但标准 UIButtons 会受到 tintColor 设置的影响。

尝试在注释视图上显式设置tintColor:

annotationView.tintColor = [UIColor blueColor];

【讨论】:

    【解决方案2】:

    tintColor 对我不起作用,所以在玩了一些之后我得到了它。

    诀窍是为图像设置一个框架。详细信息披露按钮有效,因为它已经设置了大小:

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

    【讨论】:

      猜你喜欢
      • 2016-11-07
      • 1970-01-01
      • 2023-03-15
      • 2013-10-30
      • 2020-11-24
      • 1970-01-01
      • 1970-01-01
      • 2017-12-19
      • 2013-12-09
      相关资源
      最近更新 更多