我使用带有"setInputView“函数的自定义键盘实现了文本字段。但我有一个问题:我的键盘框不是标准的iphone键盘框。
问题是:如何更改自定义键盘的大小?我知道一些函数,比如: UIKeyboardFrameBeginUserInfoKey,..etc。
请注意: iPhone键盘框= 0,264,320,216我的自定义键盘框= 0,0,320,460
希望您的合作,最好的问候…P
发布于 2011-10-27 03:08:21
事实证明,您分配给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.有关更详细的信息,您可以查看由 this link 提供的苹果。
如果UIKit在其自动调整大小蒙版中遇到UIViewAutoresizingFlexibleHeight值的输入视图,它会更改高度以匹配键盘。
希望这能有所帮助!
发布于 2015-03-27 17:10:02
要将键盘inputView设置为与本机键盘相同的大小,只需执行以下操作:
inputView.autoresizingMask = UIViewAutoresizingFlexibleHeight;要设置自己的框架,请执行以下操作:
inputView.autoresizingMask = UIViewAutoresizingNone;您可以非常灵活地定义输入视图或输入附件视图的大小和内容。尽管这些视图的高度可以根据您的喜好而定,但它们的宽度应该与系统键盘相同。如果UIKit在其自动调整大小的蒙版中遇到UIViewAutoresizingFlexibleHeight值的输入视图,它会更改高度以匹配键盘。对于输入视图和输入附件视图可能具有的子视图(例如控件)的数量没有限制。有关输入视图和输入附件视图的更多指导,请参见iOS人机接口指南。
发布于 2011-06-04 22:47:39
我也有同样的问题。我解决这个问题的方法是注册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;
}https://stackoverflow.com/questions/6042060
复制相似问题