我在输入文本字段时遇到了问题。在“CommentviewController”中,我有一个可滚动的表视图来显示之前的评论,底部是一个UItextField,用户可以输入评论并发布评论。问题是:当我试图在文本框中打字时,键盘被切换,文本在我打字时上下跳跃。例如,我输入的第一个字符在键盘上方,第二个字符在键盘下方和后面。有人知道原因吗?测试设备是64 GB的itouch5,代码是用objective C写的,而我使用的是Xcode6.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> 发布于 2015-07-30 02:40:06
您是否正在更改tableView的滚动位置
UITableView将自动滚动,以便UITextField在被选中时不会被键盘隐藏,并弹出键盘。如果您正在更改滚动位置,这可能会干扰自动滚动行为。
https://stackoverflow.com/questions/31706393
复制相似问题