自定义键盘:inputView:如何更改键盘大小?

发布于 2024-11-08 14:25:35 字数 239 浏览 0 评论 0原文

我使用带有“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

不美如何 2024-11-15 14:25:35

事实证明,您分配给 UITextField 属性的自定义输入视图的默认行为是将视图大小调整为与默认键盘相同的框架。尝试设置(我使用名称 InputViewController 作为我的输入视图,但您可以使用任何您想要的):

inputViewController = [[InputViewController alloc] initWithNibName:@"InputViewController" bundle:nil];
inputViewController.delegate = self;
inputViewController.view.autoresizingMask = UIViewAutoresizingNone; // This is the code that will make sure the view does not get resized to the keyboards frame.

有关更详细的信息,您可以查看 此链接,由 Apple 提供:

如果 UIKit 遇到在其自动调整大小掩码中具有 UIViewAutoresizingFlexibleHeight 值的输入视图,它会更改高度以匹配键盘。

希望有帮助!

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 name InputViewController for my input view, but you can use whatever you want):

inputViewController = [[InputViewController alloc] initWithNibName:@"InputViewController" bundle:nil];
inputViewController.delegate = self;
inputViewController.view.autoresizingMask = UIViewAutoresizingNone; // This is the code that will make sure the view does not get resized to the keyboards frame.

For more detailed information, you can look at this link, which is provided by Apple.:

If UIKit encounters an input view with an UIViewAutoresizingFlexibleHeight value in its autoresizing mask, it changes the height to match the keyboard.

Hope that Helps!

彡翼 2024-11-15 14:25:35

要将键盘 inputView 设置为与本机键盘大小相同,只需执行以下操作:

inputView.autoresizingMask = UIViewAutoresizingFlexibleHeight;

要设置自己的框架,请执行以下操作:

inputView.autoresizingMask = UIViewAutoresizingNone;

来自 Apple

您可以非常灵活地定义输入视图或输入附件视图的大小和内容。尽管这些视图的高度可以是您想要的,但它们应该与系统键盘的宽度相同。如果 UIKit 遇到在其自动调整大小掩码中具有 UIViewAutoresizingFlexibleHeight 值的输入视图,它会更改高度以匹配键盘。输入视图和输入附件视图可能具有的子视图(例如控件)的数量没有限制。有关输入视图和输入附件视图的更多指南,请参阅 iOS 人机界面指南。

To set the keyboard inputView with the same size as the native keyboard just do this:

inputView.autoresizingMask = UIViewAutoresizingFlexibleHeight;

To set your own frame do this:

inputView.autoresizingMask = UIViewAutoresizingNone;

From Apple:

You have a lot of flexibility in defining the size and content of an input view or input accessory view. Although the height of these views can be what you’d like, they should be the same width as the system keyboard. If UIKit encounters an input view with a UIViewAutoresizingFlexibleHeight value in its autoresizing mask, it changes the height to match the keyboard. There are no restrictions on the number of subviews (such as controls) that input views and input accessory views may have. For more guidance on input views and input accessory views, see iOS Human Interface Guidelines.

囍笑 2024-11-15 14:25:35

我也有同样的问题。我通过注册 UIKeyboardDidShowNotification 解决了这个问题(不幸的是,UIKeyboardWillShowNotification 不起作用),然后在显示键盘后更改视图大小。然而,当它向上移动时,键盘顶部仍然有一个白色的盒子。这对我来说效果很好,因为它是通过具有白色背景的 UITextView 进入的。但是,如果您进入任何其他彩色对象,在正确调整视图大小之前,它看起来会有点难看。您可以通过将背景颜色设置为clearColor来解决这个问题。

// Add this while initializing your view
self.backgroundColor = [UIColor clearColor]; // Needed because we can't resize BEFORE showing the view.  Otherwise you will see an ugly white box moving up w/ the keyboard
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardWasShown:)
                                             name:UIKeyboardDidShowNotification object:nil];



// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{

    CGRect rect = self.frame;
    rect.size.height = 164;
    self.frame = rect;

}

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.

// Add this while initializing your view
self.backgroundColor = [UIColor clearColor]; // Needed because we can't resize BEFORE showing the view.  Otherwise you will see an ugly white box moving up w/ the keyboard
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardWasShown:)
                                             name:UIKeyboardDidShowNotification object:nil];



// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{

    CGRect rect = self.frame;
    rect.size.height = 164;
    self.frame = rect;

}
过期以后 2024-11-15 14:25:35

另外,如果您使用 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.

卷耳 2024-11-15 14:25:35

对我来说,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:

enter image description here

I applied this just for the outermost view.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文