码迷,mamicode.com
首页 > 移动开发 > 详细

ios开发之--键盘的监听

时间:2017-07-13 19:01:43      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:rmi   center   duration   ica   server   net   eva   fine   enter   

监听键盘的弹出,让整个页面向上移动,比较简单,仅做记录使用:

代码如下:

 // 监听键盘
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShowAction:) name:UIKeyboardWillShowNotification object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHideAction:) name:UIKeyboardWillHideNotification object:nil];

键盘处理:

#pragma mark - 键盘处理

/**
 *  键盘即将隐藏
 */
- (void)keyboardWillHideAction:(NSNotification *)note
{
    
    // 1.键盘弹出需要的时间
    CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    
    // 2.动画
    [UIView animateWithDuration:duration animations:^{
        self.view.transform = CGAffineTransformIdentity;
    }];
}

/**
 *  键盘即将弹出
 */
- (void)keyboardWillShowAction:(NSNotification *)note
{
    
    // 1.键盘弹出需要的时间
    CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    
    // 2.动画
    [UIView animateWithDuration:duration animations:^{
        // 取出键盘高度
        CGRect keyboardF = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
        CGFloat keyboardH = keyboardF.size.height - 40;
        if (_ThreeInch) {
            self.view.transform = CGAffineTransformMakeTranslation(0, - keyboardH);
        } else {
            self.view.transform = CGAffineTransformMakeTranslation(0, - 50);
        }
    }];
}

 

ios开发之--键盘的监听

标签:rmi   center   duration   ica   server   net   eva   fine   enter   

原文地址:http://www.cnblogs.com/hero11223/p/7161850.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!