gpt4 book ai didi

ios - 按下 TextField 时向上移动 UIView

转载 作者:行者123 更新时间:2023-12-01 18:00:35 25 4
gpt4 key购买 nike

我有 2 个文本字段,如果单击文本字段(在纵向模式下),键盘不会隐藏文本字段。但是当我更改为 Landscape 时,键盘会覆盖 textFields。我不知道如何在委托(delegate)方法(textFieldShouldBeginEditing,textFieldShouldEndEditing)中设置帧大小,以便它可以在纵向和横向上工作。或者我应该使用 ScrollView 吗? enter image description here

enter image description here

最佳答案

您必须使用 scrollView并将其他 UI 元素作为 ScrollView 的 subview .和框架尺寸为scrollView即使在 Landscape Mode 中也应该使用整个窗口大小也(为此你需要学习 autoresizingmask ).. 然后当你调用 textFieldkeyboard appears ,您需要减小我们的 scrollView 的大小即使您的键盘在 View 中,也可以滚动框架..

下面是我的 textFieldDidBeginEditing 和 textFieldDidEndEditing 方法的代码:

- (void)textFieldDidBeginEditing:(UITextField *)textField
{

[UIView beginAnimations: nil context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: 0.2];
scrollView.frame = CGRectMake(0,0,320,150);
[scrollView scrollRectToVisible:textField.frame animated:YES];
[UIView commitAnimations];

}


- (void)textFieldDidEndEditing:(UITextField *)textField
{

[self autoCalculateDownPayment];
[UIView beginAnimations: nil context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: 0.2];
scrollView.frame = CGRectMake(0,0,320,416);
[UIView commitAnimations];
}

关于ios - 按下 TextField 时向上移动 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10536760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com