监听键盘

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];


#pragma mark 监听方法
- (void)keyboardChangeFrame :(NSNotification *)note
{
    CGFloat time = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    CGRect rect = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGFloat endY = rect.origin.y;
    [UIView animateWithDuration:time animations:^{
        self.view.transform = CGAffineTransformMakeTranslation(0, endY - [UIScreen mainScreen].bounds.size.height);
    }];
}

 

posted @ 2015-12-22 21:08  N了歌C  阅读(145)  评论(0编辑  收藏  举报