如何显示UIView的键盘 [英] How to show the keyboard for a UIView

查看:89
本文介绍了如何显示UIView的键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIView,我想在其中接收键盘输入.我已经尝试过:

I have a UIView where I want to receive keyboard input. I have tried:

[self becomeFirstResponder];

但是它不起作用.

我可以通过隐藏UITextField并将按键转发到我的UIView来实现肮脏"的解决方法-但是我的UIView如何直接接收键盘输入?

I could implement a 'dirty' workaround by having a hidden UITextField and forwarding the keystokes to my UIView - but how does my UIView receive the keyboard input directly?

推荐答案

要使视图成为第一响应者并显示键盘,它必须采用并实现UIKeyInput协议.它还必须重写canBecomeFirstResponder方法以返回YES.

For a view to become first responder and show the keyboard, it must adopt and implement the UIKeyInput protocol. It must also override the canBecomeFirstResponder method to return YES.

请参见

See "Simple Text Input" in the Text Programming Guide for iOS.

这篇关于如何显示UIView的键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆