gpt4 book ai didi

ios - 触发 UITextField 时,同步向上滑动 UIView 并调整 UITableView 的大小

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:17:16 25 4
gpt4 key购买 nike

我想调整 UITableView 的大小并向上滑动包含 UITextFieldUIView,当此字段被触发时。这是两个简单的模型:

enter image description here enter image description here

现在我有了这段代码:

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.3];
[UIView setAnimationBeginsFromCurrentState:YES];

[myView setFrame:CGRectMake(myView.frame.origin.x, myView.frame.origin.y - 167, myView.frame.size.width, myView.frame.size.height)]; // 216 (keyboard's height) - 49 (tabbar's height) = 167

[UIView commitAnimations];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.3];
[UIView setAnimationBeginsFromCurrentState:YES];

[myView setFrame:CGRectMake(myView.frame.origin.x, myView.frame.origin.y + 167, myView.frame.size.width, myView.frame.size.height)];

[UIView commitAnimations];
return TRUE;
}

问题是键盘上滑动画和myView上滑动画不同步。如何让这两个动画完美同步?

以及如何在键盘可见时调整 UITableView 的大小,并在键盘隐藏时返回到原始高度?

最佳答案

简短的回答是您需要订阅 UIKeyboardWillShowNotificationUIKeyboardWillHideNotification。这些通知包含键盘动画的确切参数。

长答案是 https://stackoverflow.com/a/8704371/77567 .

关于您的标签栏:我链接的答案假设您希望在键盘关闭时将 View 向下滑动到屏幕的底部边缘。由于要将其向下滑动到标签栏的边缘,因此需要查看键盘是隐藏还是显示(通过检查 note.name)。如果它正在显示,您应该将 View 的当前帧保存在一个实例变量中。如果它是隐藏的,您应该将 View 的新框架设置为您保存在实例变量中的那个框架,而不是根据键盘的结束框架来设置它。

关于ios - 触发 UITextField 时,同步向上滑动 UIView 并调整 UITableView 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9152014/

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