我有一个相当基本的界面,通常看起来像这样:
相当缺乏灵感,但这就是规范所说的构建。无论如何,部分问题是当屏幕键盘弹出时,会发生这种情况:
现在这本身并不是一个大问题。我已经将所有内容都包含在 aUIScrollView
中,并且正在使用以下代码来处理键盘的显示和隐藏:
- (void) moveTextViewForKeyboard:(NSNotification*)aNotification up: (BOOL) up{
NSDictionary* userInfo = [aNotification userInfo];
// Get animation info from userInfo
NSTimeInterval animationDuration;
UIViewAnimationCurve animationCurve;
CGRect keyboardEndFrame;
[[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
[[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
[[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];
// Animate up or down
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:animationDuration];
[UIView setAnimationCurve:animationCurve];
CGRect newFrame = referrerInfoView.frame;
CGRect keyboardFrame = [self.view convertRect:keyboardEndFrame toView:nil];
newFrame.size.height -= (keyboardFrame.size.height - 71) * (up? 1 : -1);
referrerInfoView.frame = newFrame;
referrerInfoView.contentSize = CGSizeMake(703, 633);
//FIXME: doesn't play nice with rotation when the keyboard is displayed
if (up && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
UIView* focusedField = [referrerInfoView findFirstResponder];
if (focusedField && focusedField.frame.origin.y > 340.0) {
referrerInfoView.contentOffset = CGPointMake(0.0, focusedField.frame.origin.y - 200.0);
}
}
else {
referrerInfoView.contentOffset = CGPointMake(0.0, 0.0);
}
[UIView commitAnimations];
}
不是世界上最强大的东西,但它现在已经足够好了。这让我到了这里:
现在这很好,除了在键盘保持在屏幕上时,阴影框中的任何元素都不会响应用户交互。UIScrollView
响应交互,视图中的所有其他控件也是如此。但是所有“地址”字段都停止工作。
从本质上讲,在我将它们滚动回视图之前隐藏在键盘后面的所有控件似乎仍然认为它们被隐藏在键盘后面。有想法该怎么解决这个吗?