gpt4 book ai didi

ios - 如何在动态创建的文本字段中设置 ScrollView 的内容偏移量?

转载 作者:行者123 更新时间:2023-11-29 04:26:25 28 4
gpt4 key购买 nike

我已将动态创建的文本字段放置在 ScrollView 中。我需要为 ScrollView 设置 contentOffset。在文本字段中应该开始编辑我已经给出了 ScrollView 。如果我遍历“完成”按钮,效果很好。但在这之间,如果我点击任何文本字段,该文本字段就会上升,并且我看不到该文本字段。它显示下一个字段偏移量,但光标位于正确的文本字段中。我的代码是

  -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField

{

if(enteredHealthyHeart)
{
for(int i=0;i<[healthyHeart_TxtFldAry count];i++)
{
if(textField == [healthyHeart_TxtFldAry objectAtIndex:i])
{
getHHTag=textField.tag;
NSLog(@"getHHTag %i",getHHTag);
UITextField *tempTxtFld=[healthyHeart_TxtFldAry objectAtIndex:getHHTag];

if(i<([healthyHeart_TxtFldAry count]-1))
{
int j =tempTxtFld.frame.origin.y;

healthyHeartScrollView.contentOffset=CGPointMake(0 , j);

NSLog(@"j>>>>>%i",j);
}
if(i==([healthyHeart_TxtFldAry count]-1))
{
healthyHeartScrollView.contentOffset=CGPointMake(0 ,tempTxtFld.frame.origin.y);

}

[tempTxtFld resignFirstResponder];

return YES;

}
}

}

请帮我解决这个问题。

最佳答案

首先为每个UITextField添加标签;

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
//Take reference of all UITextField u added let say u have 3;
UITextField *txt = (UItextField *)[self.view viewWithTag:99];
UITextField *txt1 = (UItextField *)[self.view viewWithTag:199];
UITextField *txt2 = (UItextField *)[self.view viewWithTag:299];

if(textField == txt)
{
[txt1 resignFirstResponder];
[txt2 resignFirstResponder];
//required scroll view offset here
}
if(textField == txt1)
{
[txt resignFirstResponder];
[txt2 resignFirstResponder];
//required scroll view offset here
}
if(textField == txt2)
{
[txt resignFirstResponder];
[txt1 resignFirstResponder];
//required scroll view offset here
}
return YES;
}

关于ios - 如何在动态创建的文本字段中设置 ScrollView 的内容偏移量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12276055/

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