gpt4 book ai didi

ios - 用户界面文本域 : Text jumps up and down while typing

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:13:43 26 4
gpt4 key购买 nike

我在文本字段输入方面遇到问题。在“CommentviewController”中,我有一个可滚动的表格 View 来显示以前的评论,底部是一个 UItextField,供用户输入评论并发布。问题是:当我尝试在文本字段中键入内容并且键盘处于切换状态时,文本会在我键入时上下跳动。例如,我键入的第一个字符在键盘上方,第二个字符在键盘下方和后面。有人知道原因吗?测试设备是64GB的itouch5,代码是objective C写的,我用的是Xcode 6.3.2。

    <i>`- (void)keyboardWasShown:(NSNotification*)aNotification {
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
theKBSize = kbSize;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height - 10, 0.0);
self.tvComment.contentInset = contentInsets; self.tvComment.scrollIndicatorInsets = contentInsets;
CGRect uvFrame = _uvComment.frame;
uvFrame.origin.y = self.view.frame.size.height - kbSize.height - _uvComment.frame.size.height; _uvComment.frame = uvFrame; } `</i>

<i> `- (void)keyboardWillBeHidden:(NSNotification*)aNotification {
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
_tvComment.contentInset = contentInsets;
_tvComment.scrollIndicatorInsets = contentInsets;
}`</i>

<i>`- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if(string==nil || [string length]<1) {
[self.btnSend setEnabled: NO];
}else {
[self.btnSend setEnabled: YES];
}
return YES;
}`</i>

最佳答案

您是否正在更改 tableView 的滚动位置?

UITableView 将自动滚动,以便 UITextField 在被选中时不会被键盘隐藏,并且键盘会弹出。如果您要更改滚动位置,这可能会干扰自动滚动行为。

关于ios - 用户界面文本域 : Text jumps up and down while typing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31706393/

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