#pragma mark -

#pragma mark Keyboard notifications from Apple's UICatalog example

//The code comes straight from Apple's UICatalog example, except that I have modified the UI manipulation

//to use bounds instead of frame, so that when keyboard is shown, the view "scrolls" to the right place

//so that the input field would remain visible.

- (void)keyboardWillShow:(NSNotification *)aNotification {

  // the keyboard is showing so resize the my height

  CGRect keyboardRect = [[[aNotification userInfoobjectForKey:UIKeyboardBoundsUserInfoKeyCGRectValue];

  NSTimeInterval animationDuration = [[[aNotification userInfoobjectForKey:UIKeyboardAnimationDurationUserInfoKey]                            doubleValue];

 

  CGRect bounds = self.view.bounds;

  bounds.origin.y += keyboardRect.size.height;

 

  [UIView beginAnimations:@"ResizeForKeyboard" context:nil];

  [UIView setAnimationDuration:animationDuration];

   self.view.bounds = bounds;

  [UIView commitAnimations];

}

 

- (void)keyboardWillHide:(NSNotification *)aNotification {

  // the keyboard is hiding reset the table's height

   CGRect keyboardRect = [[[aNotification userInfoobjectForKey:UIKeyboardBoundsUserInfoKeyCGRectValue];

  NSTimeInterval animationDuration = [[[aNotification userInfoobjectForKey:UIKeyboardAnimationDurationUserInfoKey]                            doubleValue];

   CGRect bounds = self.view.bounds;

   bounds.origin.y -= keyboardRect.size.height;

 

  [UIView beginAnimations:@"ResizeForKeyboard" context:nil];

  [UIView setAnimationDuration:animationDuration];

  self.view.bounds = bounds;

  [UIView commitAnimations];

}


posted on 2010-05-25 12:23  eagley  阅读(844)  评论(1编辑  收藏  举报