0
我用下面的方法来调整键盘显示/隐藏后的视图:处理键盘的显示/隐藏和方向改变
- (void)moveViewForKeyboard:(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 = self.view.frame;
CGRect keyboardFrame = [self.view convertRect:keyboardEndFrame toView:nil];
newFrame.size.height += (up? -1 : 1) * keyboardFrame.size.height;
self.view.frame = newFrame;
keyboardUp = up;
[UIView commitAnimations];
}
这个作品非常好,直到屏幕方向的变化。然后会发生的是该方法正确调整视图的大小,但在此方法返回后 - 再次将视图的大小重新调整为屏幕的最大高度。
任何想法?
问题在于,我无法找到重新调整大小的原因和位置。 – 2011-03-04 21:30:03
您是否设置了中断点并查看了调用堆栈?您的方法是第二次调用还是其他代码? – 2011-03-04 21:37:08