如何将 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];
这确实隐藏了键盘,但如果我在此视图中单击,该按钮仍然显示。我尝试使用 UIButton,但该按钮无法捕获单击。当 UIKeyboardDidShowNotification
时,我尝试 becameFirstResponder
但没有成功。
有什么想法吗?
I have a idea to hide some keys in keyboard. I use the exact background of the keyboard and use it above the keyboard.
So I create a textView and add a 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];
This really hide the keyboard, but if I click in this view, the button still show. I try to use a UIButton, but the button don't catch the click. And I try becameFirstResponder
when UIKeyboardDidShowNotification
and no success.
Any Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将附件视图的
userInteractionEnabled
设置为 YES。这会让你的视野吞噬所有的接触。不过,如果您想要自定义视图进行编辑,则可以通过为字段设置特定的编辑视图来实现此目的,而不是尝试在键盘顶部放置其他内容。
You can set
userInteractionEnabled
to YES for your accessory view. This will make your view swallow all the touches.If you want a custom view for editing, though, you can do this by setting a specific editing view for your field rather than trying to put something else on top of the keyboard.