自定义键盘:inputView:如何更改键盘大小?
我使用带有“setInputView”函数的自定义键盘实现了文本字段。 但我有一个问题:我的键盘框架不是标准的 iPhone 键盘框架。
问题是: 如何更改自定义键盘的大小? 我知道一些函数,例如:UIKeyboardFrameBeginUserInfoKey,..等。
请注意: iPhone键盘框=0,264,320,216 我的自定义键盘框架是 = 0,0,320,460
希望您的友好合作, 此致... 磷
I implemented the textfield with a custom keyboard with the "setInputView" function.
But i have a problem: my keyboard frame is not a standard iphone keybord frame.
The question is:
How can i change the size of my custom keyboard?
I know some functions like: UIKeyboardFrameBeginUserInfoKey, ..etc.
Please Note:
The iPhone keyboard frame is = 0,264,320,216
My custom keyboard frame is = 0,0,320,460
Hoping for your kind collaboration,
Best regards...
P
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
事实证明,您分配给 UITextField 属性的自定义输入视图的默认行为是将视图大小调整为与默认键盘相同的框架。尝试设置(我使用名称
InputViewController
作为我的输入视图,但您可以使用任何您想要的):有关更详细的信息,您可以查看 此链接,由 Apple 提供:
希望有帮助!
It turns out that the default behaviour of the custom input view that you assign to the
UITextField
's property is to resize the view to the same frame as the default keyboard. Try setting (I use the nameInputViewController
for my input view, but you can use whatever you want):For more detailed information, you can look at this link, which is provided by Apple.:
Hope that Helps!
要将键盘 inputView 设置为与本机键盘大小相同,只需执行以下操作:
要设置自己的框架,请执行以下操作:
来自 Apple:
To set the keyboard inputView with the same size as the native keyboard just do this:
To set your own frame do this:
From Apple:
我也有同样的问题。我通过注册 UIKeyboardDidShowNotification 解决了这个问题(不幸的是,UIKeyboardWillShowNotification 不起作用),然后在显示键盘后更改视图大小。然而,当它向上移动时,键盘顶部仍然有一个白色的盒子。这对我来说效果很好,因为它是通过具有白色背景的 UITextView 进入的。但是,如果您进入任何其他彩色对象,在正确调整视图大小之前,它看起来会有点难看。您可以通过将背景颜色设置为clearColor来解决这个问题。
I had the same problem. I solved it by registering for UIKeyboardDidShowNotification (UIKeyboardWillShowNotification did not work, unfortunately) and then changing the view size after the keyboard was shown. However, it still had the white box on top of the keyboard when it was moving up. This worked fine for me because it is coming in over a UITextView with a white background. If you were coming in over any other colored objects, however, it would look a little ugly before the view was properly resized. You can solve that by setting the background color to clearColor.
另外,如果您使用 UIViewController 来设计 inputView,请不要使用 UIViewController.view ...无论 AutoresizeMask 如何,旋转时似乎都会出现很多错误调整大小的问题。
对我有用的是采用我现有的 UI 并使用 Editor >嵌入>看法。然后创建一个新的插座,并将该插座作为 inputView 传递。突然,旋转错误的调整大小消失了。
Also if you're using a UIViewController to design your inputView, don't use the UIViewController.view... it seems to have a lot of problems getting resized incorrectly on rotate regardless of the AutoresizeMask.
What worked for me was to take my existing UI and use Editor > Embed In > View. Then create a new outlet, and pass that outlet as the inputView. Suddenly the resize on rotate bugs disappeared.
对我来说,msgambel 的解决方案不起作用。但方法是正确的,我正在使用 inputView 的 autoresizingMask 。以前我有不同的设置,但避免自定义键盘上出现白色额外空间的正确方法是:
I仅将其应用于最外面的视图。
For me msgambel's solution didn't work. But the approach right, I was playing with the inputView's autoresizingMask. Former I had different setting, but the right way to avoid white extra space over the custom keyboard is:
I applied this just for the outermost view.