开发者

Handling keyboard show/hide & orientation changes

I use the following method to resize the view after keyboard show/hide:

- (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 se开发者_如何学GotAnimationDuration: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];
}

This works very good, until the screen orientation changes. What happens then is that the method resizes the view correctly, but after this method returns - something else resizes the view again to the maximum height of the screen.

Any ideas?


First you'll need to figure out what is resizing the view again. I would recommend putting a breakpoint into the above method so when it gets called that 2nd, unwanted time, you can look at the method call stack and see what is causing the 2nd call. Then you'll be able to stop it from happening, or change your code so that it doesn't cause a problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜