我正在调试别人的代码——抱歉,我的 Objective-C 经验非常有限。
#pragma mark - Keyboard events
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
NSLog(@"Keyboard a Notification user Info %@", info);
printf("keyboardWasShown \\\\\\\\\\\\\\\\\\\\\n");
NSLog(@"textInputView: y: (%.f), height: (%.f), kbHeight: (%.f)",
textInputView.frame.origin.y, textInputView.frame.size.height, kbSize.height);
[UIView animateWithDuration:2.0f animations:^{
if (keyboardNewLine){
bubbleTableFrame = originalBubbleTableFrame;
}
CGRect frame = originalTextViewFrame;
int difference = 0;
if (IsIphone5){
difference = -42;
frame.origin.y -= kbSize.height + difference;
} else {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f) {
difference = 42;
frame.origin.y -= kbSize.height + difference;
} else {
frame.origin.y -= kbSize.height + 110;
difference = 42;
}
}
textInputView.frame = frame;
frame = bubbleTableFrame;
frame.size.height -= kbSize.height + difference;
bubbleTable.frame = frame;
}];
NSLog(@"textInputView: y: (%.f), height: (%.f), kbHeight: (%.f)",
textInputView.frame.origin.y, textInputView.frame.size.height, kbSize.height);
printf("keyboardWasShown //////////\n");
[bubbleTable scrollBubbleViewToBottomAnimated:YES];
}
当我点击文本输入字段以调出键盘时,该字段应向上移动到键盘上方 - 有时。这完全取决于首先加载哪个键盘。
- 没有键盘的文本字段:
- 点击文本字段后,我期望:
- 然而,文本字段停留在屏幕底部,只留下占位符:
- 奇怪的是,如果我往下拉 QuickType 行,文本字段会突然出现!
- 但是,如果我退出该视图并随后返回,文本字段再次卡在底部(猜猜看,如果我向上拖动 QuickType 行,它会跳起来):
- 通过点击地球图标切换到另一个键盘(输入法)总是有助于调出文本字段:
- 似乎第三方键盘不受影响:
你可以看到我一直在监控textInputView.frame.origin.y看看出了什么问题。它从 472(无键盘)更改为 261(英文键盘),但文本字段根本不会上升。
我不认为它在占位符后面(如果有的话),因为当我点击气泡旁边的白色区域时,键盘会向下移动并显示卡在底部的文本字段。
有人建议添加 setNeedsDisplay、setNeedsLayout 等,但没有任何帮助。
提前致谢。