【问题标题】:Only center of UIButton is clickable只有 UIButton 的中心是可点击的
【发布时间】:2015-01-30 13:15:16
【问题描述】:

我将自定义 UIButton 添加到 MKAnnotationView(地图上的“图钉”,而不是“气泡”),但是当我这样做时,只有按钮的中心是可点击的。

这是我的按钮的方法:

- (UIButton *)button: (NSString*)text{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setFrame:CGRectMake(0, 0, 100, 100)];
    [[button titleLabel] setLineBreakMode:NSLineBreakByWordWrapping];
    text=[NSString stringWithFormat:@"%@",text];
    [button setTitle:text forState:UIControlStateNormal];
}

这里我将它添加到 MKAnnotationView 中:

buildingBtn = [self button:annotations.title];    
[self addSubview:buildingBtn];
buildingBtn.layer.anchorPoint = CGPointMake(1, 1);

【问题讨论】:

    标签: ios uibutton mkannotationview


    【解决方案1】:

    您的UIButton 的框架可能比MKAnnotationView 的框架大。如果是这种情况,按钮将不会接收到位于注释视图边界之外的任何触摸。

    【讨论】:

      【解决方案2】:

      (从问题作者重新发布的答案材料将其移动到答案空间)

      感谢@Muncken,找到了解决方案。

      MKAnnotationView 的框架未设置。通过自己设置,我可以控制可点击的大小。我还发现将 UIButton 添加到 MKAnnotationView 是没有意义的,因为 MKAnnotationView 充当按钮。

      【讨论】:

        猜你喜欢
        • 2016-11-15
        • 1970-01-01
        • 1970-01-01
        • 2012-05-10
        • 1970-01-01
        • 2016-03-05
        • 2010-11-07
        • 1970-01-01
        • 2015-09-14
        相关资源
        最近更新 更多