键盘隐藏的文本字段

时间:2012-12-27 09:37:58

标签: ios uitextfield iphone-softkeyboard

我有几个textfield,当可见时被键盘遮挡。我认为当键盘可见时我需要移动视图。我如何检测到这一点?

5 个答案:

答案 0 :(得分:3)

检查“文字,网页和编辑iOS编程指南”中的Managing the Keyboard - Receiving Keyboard Notifications部分:http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html

When the keyboard is shown or hidden, iOS sends out the following notifications to any registered observers:

UIKeyboardWillShowNotification UIKeyboardDidShowNotification UIKeyboardWillHideNotification UIKeyboardDidHideNotification

答案 1 :(得分:1)

也许您正在寻找this来检测何时键盘在可编辑的文本字段中可见。

答案 2 :(得分:0)

我认为你是iOS的新手。

我认为您的视图包含5到10个文本字段,并且将逐个输入文本。

如果这是您的情况,请将所有文本字段放在uiscrollview中,以便在需要时向下滚动。

这是所有程序员都遵循的正常方法。

如果这是你的情况而不是告诉我,我可能会给你一些示例链接。

答案 3 :(得分:0)

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.35f]; 
CGRect frame = self.view.frame; 
frame.origin.y = -60; 
[self.view setFrame:frame]; 
[UIView commitAnimations];
[textField resignFirstResponder];

如果您希望将视图设置在与之前相同的位置,则可以使用此代码上下移动视图,然后您可以使用相同的代码

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.35f]; 
CGRect frame = self.view.frame; 
frame.origin.y = 0; 
[self.view setFrame:frame]; 
[UIView commitAnimations];
[textField resignFirstResponder];

但y的不同值你可以使用frame.origin.y并相应地调整它。

答案 4 :(得分:0)

This文档包含您需要的所有代码

相关问题