标注附件按钮显示,但不可见

时间:2014-09-04 17:13:46

标签: ios mkmapview

我的应用中有一张地图,显示了我自己项目的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上。

2 个答案:

答案 0 :(得分:1)

目前尚不清楚为什么您的配件按钮“不可见”,但标准UIButtontintColor设置的影响。

尝试在注释视图上明确设置tintColor

annotationView.tintColor = [UIColor blueColor];

答案 1 :(得分: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;