Iphone 处理键盘显示/隐藏&;方向改变
在键盘显示/隐藏后,我使用以下方法调整视图的大小:Iphone 处理键盘显示/隐藏&;方向改变,iphone,objective-c,ipad,ios,Iphone,Objective C,Ipad,Ios,在键盘显示/隐藏后,我使用以下方法调整视图的大小: - (void)moveViewForKeyboard:(NSNotification*)aNotification up:(BOOL)up { NSDictionary* userInfo = [aNotification userInfo]; // Get animation info from userInfo NSTimeInterval animationDuration; UIViewAnimationC
- (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];
}
这非常有效,直到屏幕方向改变。然后发生的事情是,该方法正确地调整了视图的大小,但是在该方法返回后,其他的东西会将视图重新调整到屏幕的最大高度
有什么想法吗?首先,您需要弄清楚是什么在重新调整视图的大小。我建议在上述方法中设置一个断点,以便在第二次调用时,您可以查看方法调用堆栈并查看导致第二次调用的原因。然后您就可以阻止它发生,或者更改代码,使其不会引起问题。问题在于,我无法找到它再次调整大小的原因和位置。您是否设置了断点并查看了调用堆栈?您的方法是第二次调用还是其他代码?