[英]Handling keyboard show/hide & orientation changes
在鍵盤顯示/隱藏后,我使用以下方法調整視圖的大小:
- (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];
}
直到屏幕方向發生變化,這都很好。 然后發生的是該方法正確地調整了視圖的大小,但是在此方法返回后,其他方法再次將視圖的大小調整到了屏幕的最大高度。
有任何想法嗎?
首先,您需要找出重新調整視圖大小的內容。 我建議在上面的方法中放置一個斷點,這樣當它被調用到第二個不需要的時間時,您可以查看方法調用堆棧並查看導致第二個調用的原因。 然后,您將能夠阻止它的發生,或者更改您的代碼以使其不會引起問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.