2011-09-16 49 views
2

我有一个想法来隐藏键盘上的一些键。我使用键盘的确切背景并在键盘上方使用它。如何把UIView放在键盘上方

所以我创建一个TextView并添加accessoryView的

//Create the view 
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, -10, 768, 300)]; 
[view setBackgroundColor:[UIColor greenColor]] 

UITextField text = [[UITextField alloc] initWithFrame:CGRectMake(120, 10, 80, 28)]; 
[text setKeyboardType:UIKeyboardTypeNumbersAndPunctuation]; 
[text setInputAccessoryView:view]; 

enter image description here 这确实隐藏键盘,但如果我在这个视图中单击,按钮仍然显示。我尝试使用UIButton,但该按钮无法捕捉点击。而我试试becameFirstResponderUIKeyboardDidShowNotification并没有成功。

任何想法?

回答

0

您可以将userInteractionEnabled设置为YES以查看附件视图。这会让你的视野吞噬所有的触觉。

但是,如果您想要自定义视图进行编辑,您可以通过为字段设置特定的编辑视图来完成此操作,而不是尝试在键盘上放置其他内容。

+0

我没有找到'userInputEnable',而是找到'userInteractionEnabled'。但是,我使用它并且不起作用。 – Rodrigo