您的位置:首页 > 其它

键盘遮挡

2015-05-13 20:38 288 查看
- (void)viewWillAppear:(BOOL)animated
{
    [super
viewWillAppear:animated];
    [[NSNotificationCenter
defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
    [[NSNotificationCenter
defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super
viewDidDisappear:animated];
    [[NSNotificationCenter
defaultCenter] removeObserver:self
name:UIKeyboardWillShowNotification
object:nil];
    [[NSNotificationCenter
defaultCenter] removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
}

- (void)keyboardWillShow:(NSNotification *)aNotification
{
    CGRect keyboardRect = [[[aNotification
userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey]
CGRectValue];
    NSTimeInterval animationDuration = [[[aNotification
userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey]
doubleValue];
    CGRect frame =
comfirmPaymentTableView.frame;
    frame.size.height -= keyboardRect.size.height;
    [UIView
beginAnimations:@"ResizeForKeyboard"
context:nil];
    [UIView
setAnimationDuration:animationDuration];
    comfirmPaymentTableView.frame = frame;
    [UIView
commitAnimations];
}

- (void)keyboardWillHide:(NSNotification *)aNotification
{
    CGRect keyboardRect = [[[aNotification
userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey]
CGRectValue];
    NSTimeInterval animationDuration = [[[aNotification
userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey]
doubleValue];
    CGRect frame =
comfirmPaymentTableView.frame;
    frame.size.height += keyboardRect.size.height;
    [UIView
beginAnimations:@"ResizeForKeyboard"
context:nil];
    [UIView
setAnimationDuration:animationDuration];
    comfirmPaymentTableView.frame = frame;
    [UIView
commitAnimations];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  键盘遮挡