我正在调试其他人的代码 - 抱歉,我的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];
}
当我点击文本输入字段以调出键盘时,字段应该向上移动到键盘上方 - 有时。这一切都取决于首先加载哪个键盘。
你可以看到我一直在监视 textInputView.frame.origin.y 以查看出现了什么问题。它从472(无键盘)变为261(英文键盘),但文本字段根本没有上升。
我不认为它位于占位符后面(如果有的话),因为当我点击气泡旁边的白色区域时,键盘会向下移动并显示粘在底部的文本字段。
有人建议添加setNeedsDisplay,setNeedsLayout等,但没人帮忙。
提前致谢。
答案 0 :(得分:0)
最终我按照某人的建议关闭了自动布局: https://www.facebook.com/groups/cocoahk/permalink/1104922892867587/
有效。虽然我需要调整所有其他物体的位置。