简体   繁体   English

iOS:UITextField 键盘和输入视图出现错误 position

[英]iOS: UITextField keyboard and inputview appears at wrong position

I am using few UITextFields with different inputviews using Keyboards, Pickerviews etc in my iPad App.我在我的 iPad 应用程序中使用键盘、Pickerviews 等使用不同输入视图的几个 UITextFields。 Normally inputview should appear from the bottom of the screen but most of the times it appears from above the bottom - about 50 pixels.通常 inputview 应该出现在屏幕底部,但大多数时候它出现在底部上方——大约 50 像素。 I have attached couple of snapshots for this.为此,我附上了几张快照。 This is happening very randomly, but when happens once, it does same for all UITextFields.这是非常随机发生的,但是一旦发生,它对所有 UITextFields 都是一样的。 Could anyone please tell me what are the factors affect this and how to get rid of this issue?谁能告诉我影响这个的因素是什么以及如何解决这个问题? I want inputview to appear from bottom of the screen always.我希望输入视图始终从屏幕底部出现。 Please note that I don't have navigation controller, I use presentviewmodel through out my App, and have a customised navigation controller look like bottom.请注意,我没有导航 controller,我在整个应用程序中使用 presentviewmodel,并且有一个自定义导航 controller 看起来像底部。 Thanks.谢谢。

* I have noticed that this happens even for Google Map while selecting From and To Textfields. * 我注意到,在选择 From 和 To Textfields 时,即使是 Google Map 也会发生这种情况。 This must be something weird!这一定有什么奇怪的! * *

I am making sure that selected textview always resignfirstresponder by following methods.我确保通过以下方法选择的 textview 总是 resignifirstresponder。

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    selectedTextField = textField;
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    [textField resignFirstResponder];
}

- (void)donePickerViewButtonPressed
{
    [selectedTextField resignFirstResponder];
}

键盘出现在屏幕底部上方 50 像素处!

PickerView UITextField inputview 出现在屏幕底部上方 50 像素处!

I am surprised I figured this out by playing with Keyboard's settings.我很惊讶我通过玩键盘的设置来解决这个问题。 In Settings->General->Keyboard->Switch off "Split Keyboard" and it worked.在“设置”->“常规”->“键盘”->“关闭”“拆分键盘”中,它起作用了。 I have confirmed by testing switching this key on and off, When Off.我已通过测试打开和关闭此键确认,关闭时。 keyboard or any inputviews appear from the botton of screen, When ON.键盘或任何输入视图出现在屏幕底部,打开时。 keyboard/inputview appears about 50 pixels up from bottom of the screen. keyboard/inputview 出现在距屏幕底部约 50 像素的位置。 Not sure what's the relation with it though!!虽然不确定与它有什么关系!

Its because you have not resignFirstResponder your textFeild before using picker or Vice Versa.So whenever u press Done button resign your all textFeilds and when u open picker resign all textFeilds.这是因为您在使用选择器或反之亦然之前没有resignFirstResponder您的 textFeild。因此,每当您按下 Done 按钮时,您将退出所有 textFeilds,而当您打开选择器时,将退出所有 textFeild。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM