Scroll UITextField在以编程方式创建时向上滚动

Scroll UITextField在以编程方式创建时向上滚动,scroll,uitextfield,Scroll,Uitextfield,所以我不完全确定为什么会发生这种情况,我尝试了“尝试和错误”来解决它,并进行了一些广泛的研究。 不过,我似乎找不到其他人遇到过同样的问题。 我试图以编程方式创建UITextField,我使用了这段代码(我编辑了代码,使其更易于理解) 当安装到模拟器中时,它会显示出来,看起来很棒,但是当我选择文本字段时,它会自动向上滚动,直到文本大约离开框的一半。它可以让我编辑,但我只能看到一半的文本。 你知道怎么回事吗?或者如何修复它? 对不起,这有点混乱,很难解释。 谢谢你的帮助 ~approxity我也有同

所以我不完全确定为什么会发生这种情况,我尝试了“尝试和错误”来解决它,并进行了一些广泛的研究。 不过,我似乎找不到其他人遇到过同样的问题。 我试图以编程方式创建UITextField,我使用了这段代码(我编辑了代码,使其更易于理解)

当安装到模拟器中时,它会显示出来,看起来很棒,但是当我选择文本字段时,它会自动向上滚动,直到文本大约离开框的一半。它可以让我编辑,但我只能看到一半的文本。 你知道怎么回事吗?或者如何修复它? 对不起,这有点混乱,很难解释。 谢谢你的帮助


~approxity

我也有同样的问题。我意识到我是在创建UITextView而不是UITextField(废话!)


您可能遇到了同样的问题。

我也遇到了同样的问题。我意识到我是在创建UITextView而不是UITextField(废话!)

        CGRect frame = CGRectMake(<your textfield location>);
        UITextField *search= [[UITextField alloc] initWithFrame:frame];
        search.borderStyle = UITextBorderStyleRoundedRect;
        search.textColor = [UIColor blackColor];
        search.font = [UIFont systemFontOfSize:17.0];
        search.placeholder = @"Text";
        search.backgroundColor = [UIColor clearColor];
        search.autocorrectionType = UITextAutocorrectionTypeNo;
        search.keyboardType = UIKeyboardTypeDefault;
        search.returnKeyType = UIReturnKeySearch;
        search.clearButtonMode = UITextFieldViewModeWhileEditing;
        [window addSubview:search];
您可能遇到了相同的问题。

CGRect frame=CGRectMake();
        CGRect frame = CGRectMake(<your textfield location>);
        UITextField *search= [[UITextField alloc] initWithFrame:frame];
        search.borderStyle = UITextBorderStyleRoundedRect;
        search.textColor = [UIColor blackColor];
        search.font = [UIFont systemFontOfSize:17.0];
        search.placeholder = @"Text";
        search.backgroundColor = [UIColor clearColor];
        search.autocorrectionType = UITextAutocorrectionTypeNo;
        search.keyboardType = UIKeyboardTypeDefault;
        search.returnKeyType = UIReturnKeySearch;
        search.clearButtonMode = UITextFieldViewModeWhileEditing;
        [window addSubview:search];
UITextField*search=[[UITextField alloc]initWithFrame:frame]; search.borderStyle=UITextBorderStyleRoundedRect; search.textColor=[UIColor blackColor]; search.font=[UIFont systemFontOfSize:17.0]; search.placeholder=@“文本”; search.backgroundColor=[UIColor clearColor]; search.autocorrectionType=UITextAutocorrectionTypeNo; search.keyboardType=UIKeyboardTypeDefault; search.returnKeyType=UIReturnKeySearch; search.clearButtonMode=UITextFieldViewModeWhileEditing; [窗口添加子视图:搜索];
使用此代码,它将为您提供完美的结果。

CGRect frame=CGRectMake();
UITextField*search=[[UITextField alloc]initWithFrame:frame];
search.borderStyle=UITextBorderStyleRoundedRect;
search.textColor=[UIColor blackColor];
search.font=[UIFont systemFontOfSize:17.0];
search.placeholder=@“文本”;
search.backgroundColor=[UIColor clearColor];
search.autocorrectionType=UITextAutocorrectionTypeNo;
search.keyboardType=UIKeyboardTypeDefault;
search.returnKeyType=UIReturnKeySearch;
search.clearButtonMode=UITextFieldViewModeWhileEditing;
[窗口添加子视图:搜索];

使用此代码将获得完美的结果。

您确定CGRectMake中的坐标正确吗?前两个不是应该是x和y的位置吗?如果是这样的话,那么你的350就会把它从屏幕上移开,除非你处于横向模式。哦,是的,我应该加上这个代码是针对Ipad和Iphone的。你确定你在CGRectMake中的坐标是正确的吗?前两个不是应该是x和y的位置吗?如果是这样的话,那么你的350就是把它从屏幕上移开了,除非你处于横向模式。哦,是的,我应该补充一下,这段代码是针对Ipad和Iphone的。
        CGRect frame = CGRectMake(<your textfield location>);
        UITextField *search= [[UITextField alloc] initWithFrame:frame];
        search.borderStyle = UITextBorderStyleRoundedRect;
        search.textColor = [UIColor blackColor];
        search.font = [UIFont systemFontOfSize:17.0];
        search.placeholder = @"Text";
        search.backgroundColor = [UIColor clearColor];
        search.autocorrectionType = UITextAutocorrectionTypeNo;
        search.keyboardType = UIKeyboardTypeDefault;
        search.returnKeyType = UIReturnKeySearch;
        search.clearButtonMode = UITextFieldViewModeWhileEditing;
        [window addSubview:search];