【发布时间】:2012-12-27 09:37:58
【问题描述】:
我有几个textfield,在可见时会被键盘遮挡。我想当键盘可见时我需要向上移动视图。如何检测到这一点?
【问题讨论】:
-
@Kalpesh 你的代码应该做什么?如果您打算提供帮助,请提供描述,而不仅仅是我作为新手理解的代码。
-
看看这个solution
标签: ios uitextfield iphone-softkeyboard
我有几个textfield,在可见时会被键盘遮挡。我想当键盘可见时我需要向上移动视图。如何检测到这一点?
【问题讨论】:
标签: ios uitextfield iphone-softkeyboard
检查 iOS 文本、Web 和编辑编程指南中的 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
【讨论】:
也许您正在寻找this 来检测键盘何时在可编辑的文本字段上可见。
【讨论】:
我认为你是 iOS 新手。
我认为您的视图包含 5 - 10 个文本字段,并且使用将一一输入文本。
如果这是您的情况,请将所有文本字段放在 uiscrollview 中,以便您可以在需要时向上滚动。
这是所有程序员都遵循的正常方法。
如果这是您的情况,请告诉我,我可以给您一些示例链接。
【讨论】:
[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 并相应地调整它..
【讨论】:
This 文档包含您需要的所有代码
【讨论】: