【问题标题】:UIButton added to inputAccessoryView not detecting touches添加到 inputAccessoryView 的 UIButton 未检测到触摸
【发布时间】:2014-10-20 14:16:19
【问题描述】:

我有一个inputAccessoryView,其中包括一个UIButton,但UIButton 没有响应点击(甚至没有改变它的图像)。我不确定为什么。这是我相当简单的代码:

UIImageView *accessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];

UIButton *selectionModeOkButton = [[UIButton alloc] initWithFrame:CGRectMake(264, 11, 50, 46)];
[selectionModeOkButton setImage:[UIImage imageNamed:@"btn_count_ok_unpressed"] forState:UIControlStateNormal];
[selectionModeOkButton setImage:[UIImage imageNamed:@"btn_count_ok_pressed"] forState:UIControlStateHighlighted];
[selectionModeOkButton addTarget:self action:@selector(selectionModeOkButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[accessoryView addSubview:selectionModeOkButton];

self.selectionModeTextField.inputAccessoryView = accessoryView;

【问题讨论】:

    标签: ios objective-c xcode uibutton inputaccessoryview


    【解决方案1】:

    来自Apple docs for UIImageView

    一个布尔值,用于确定是否忽略用户事件并将其从事件队列中删除。

    该属性继承自 UIView 父类。此类将该属性的默认值更改为 NO。

    这告诉您,默认情况下,新的UIImageViews 将userInteractionEnabled 设置为NO。所以,添加这一行:

    accessoryView.userInteractionEnabled = YES;
    

    要详细了解userInteractionEnabled 的工作原理,请查看Apple docs for UIView(继承该属性的类)中该属性的条目。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多