gpt4 book ai didi

objective-c - 键盘出现时向上滑动表格

转载 作者:太空狗 更新时间:2023-10-30 04:01:29 27 4
gpt4 key购买 nike

你好,我正在使用表格输入数据,一些文本字段位于表单的底部。当我点击文本字段进行书写时,键盘出现并隐藏了它后面的字段。如果我使文本字段成为第一响应者,它会隐藏键盘,但是通过这样做我无法做到这一点。我想知道当键盘出现时,整个表格应该如何向上移动,就像我最后一个字段出现在键盘操作上一样提前致谢

最佳答案

在 ScrollView 中添加所有 View 并设置 ScrollView 和文本字段的委托(delegate),然后使用这些委托(delegate)和方法 -

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

[self scrollViewToCenterOfScreen:textField];
return YES;

}

-(BOOL) textFieldShouldReturn:(UITextField *)textField{

if ([textField isEqual:txtField1])
{
[txtField2 becomeFirstResponder];
}
else if ([textField isEqual:txtField2])
{
[txtField3 becomeFirstResponder];
}
else
{
[textField resignFirstResponder];
[scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
}

return YES;

}

- (void)scrollViewToCenterOfScreen:(UIView *)theView {
CGFloat viewCenterY = theView.center.y;
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];

CGFloat availableHeight = applicationFrame.size.height - 200; // Remove area covered by keyboard

CGFloat y = viewCenterY - availableHeight / 2.0;
if (y < 0) {
y = 0;
}
[scrollView setContentOffset:CGPointMake(0, y) animated:YES];

}

关于objective-c - 键盘出现时向上滑动表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5893122/

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