OGeek|极客世界-中国程序员成长平台

标题: ios - UITextfield : Text jumps up and down while typing [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 09:27
标题: ios - UITextfield : Text jumps up and down while typing

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

    <i>`- (void)keyboardWasShownNSNotification*)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)keyboardWillBeHiddenNSNotification*)aNotification { 
UIEdgeInsets contentInsets = UIEdgeInsetsZero; 
_tvComment.contentInset = contentInsets;
 _tvComment.scrollIndicatorInsets = contentInsets; 
}`</i>

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



Best Answer-推荐答案


你在改变tableView的滚动位置吗?

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

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






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4