2014-10-20 53 views
0

我有一个inputAccessoryView其中包括UIButton,但UIButton没有响应水龙头(甚至没有改变它的形象)。我不知道为什么。这是我非常简单的代码:UIButton添加到inputAccessoryView没有检测到触摸

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; 

回答

1

Apple docs for UIImageView

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

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

这是告诉你的是,在默认情况下,新UIImageView■找userInteractionEnabled设置为NO。所以,加入这一行:

accessoryView.userInteractionEnabled = YES; 

欲了解更多有关如何准确userInteractionEnabled作品,请在Apple docs for UIView该属性(类从该属性继承)的条目。

相关问题