首页 > 移动平台 > 详细

iOS监听键盘事件

时间:2015-11-07 00:49:48      阅读:380      评论:0      收藏:0      [点我收藏+]
#pragma mark - view life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}#pragma mark - 通知
/**
 *   键盘弹出
 */
- (void)keyboardWillShow:(NSNotification *)note
{
    
    // 1.取出键盘的高度
    CGRect temp  = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGFloat height = temp.size.height;
    // 2.让工具条向上平移
    // 2.1取出键盘弹出的动画时间
    NSTimeInterval timte = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    [UIView animateWithDuration:timte delay:0 options:7 << 16 animations:^{
        self.bottomBar.transform = CGAffineTransformMakeTranslation(0, -height);
    } completion:nil];
    
}
/**
 *  键盘隐藏
 */
- (void)keyboardWillHide:(NSNotification *)note
{
    // 2.1取出键盘弹出的动画时间
    NSTimeInterval timte = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    
    // 清空transform
    [UIView animateWithDuration:timte delay:0 options:7 << 16 animations:^{
        
        self.bottomBar.transform = CGAffineTransformIdentity;
    } completion:nil];
    
}

 

iOS监听键盘事件

原文:http://www.cnblogs.com/songxing10000/p/4944031.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!