当键盘在横向中可见时升起视图
我的应用程序横向旋转时遇到问题。所有内容都移动到我想要的位置等,但是当键盘可见时,其中一个文本字段被覆盖。我编写了一些代码将视图向上推以解决此问题。这段代码在纵向中工作正常,但在横向中,视图会旋转回纵向。代码如下:
- (void)textFieldDidBeginEditing: (UITextField *)textField {
CGAffineTransform translation = CGAffineTransformIdentity;
if (textField == self.incVATField)
translation = CGAffineTransformMakeTranslation(0, -30);
[UIView beginAnimations:nil context:nil];
self.view.transform = translation;
[UIView commitAnimations];
}
谁能告诉我如何解决这个问题,以便当设备处于横向模式时,视图会被推高一点,这样我仍然可以看到文本字段?
谢谢
I have a problem when in landscape rotation on my App. Everything moves to where I want it etc, but when the keyboard is visible, one of the text fields is covered. I have written some code that pushes the view up to resolve this. This bit of code works fine in portrait, but in landscape, the view rotates back to portrait. The code is below:
- (void)textFieldDidBeginEditing: (UITextField *)textField {
CGAffineTransform translation = CGAffineTransformIdentity;
if (textField == self.incVATField)
translation = CGAffineTransformMakeTranslation(0, -30);
[UIView beginAnimations:nil context:nil];
self.view.transform = translation;
[UIView commitAnimations];
}
Can anyone tell me how to resolve this, so that when the device in lanscape, the view just gets pushed up a little so I can still see the text field?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当文本字段的编辑开始时,只需调整视图的框架,以便您可以看到文本。
另一种选择:
您还可以通过使视图成为滚动视图的子视图并将内容偏移更改为所需的点以使文本字段可见来实现此目的。
When the editing of the text field begins, just adjust the frame of the view so that u can see the text.
Another option:
You can also do this by making your view a sub view of scroll view and changing the content offset to the required point so that the text field is visible.