Pao*_*rea 11 textfield uikeyboard inputview
我使用带有"setInputView"功能的自定义键盘实现了文本字段.但我有一个问题:我的键盘框架不是标准的iphone键盘框架.
问题是:如何更改自定义键盘的大小?我知道一些函数,如:UIKeyboardFrameBeginUserInfoKey,.. etc.
请注意:iPhone键盘框架= 0,264,320,216我的自定义键盘框架= 0,0,320,460
希望您的合作愉快,最好的问候... P
msg*_*bel 26
事实证明,您分配给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.
Run Code Online (Sandbox Code Playgroud)
有关更多详细信息,请查看Apple提供的此链接:
如果UIKit在其自动调整掩码中遇到具有UIViewAutoresizingFlexibleHeight值的输入视图,则会更改高度以匹配键盘.
希望有帮助!
要将键盘inputView设置为与本机键盘相同的大小,只需执行以下操作:
inputView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
Run Code Online (Sandbox Code Playgroud)
要设置自己的帧,请执行以下操作:
inputView.autoresizingMask = UIViewAutoresizingNone;
Run Code Online (Sandbox Code Playgroud)
您可以在定义输入视图或输入附件视图的大小和内容方面具有很大的灵活性.虽然这些视图的高度可以是您想要的,但它们应该与系统键盘的宽度相同.如果UIKit在其自动调整掩码中遇到具有UIViewAutoresizingFlexibleHeight值的输入视图,则会更改高度以匹配键盘.输入视图和输入附件视图可能具有的子视图(例如控件)的数量没有限制.有关输入视图和输入附件视图的更多指导,请参阅iOS人机界面指南.
我有同样的问题。我通过注册 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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13854 次 |
| 最近记录: |