码迷,mamicode.com
首页 > 其他好文 > 详细

监听键盘frame变化

时间:2017-05-31 00:24:24      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:selector   code   nil   width   info   bar   cto   ext   value   

/**
 * 监听键盘的弹出和隐藏
 */
- (void)keyboardWillChangeFrame:(NSNotification *)note
{
    // 键盘最终的frame
    CGRect keyboardF = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    
    // 动画时间
    CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    
    [UIView animateWithDuration:duration animations:^{
        self.toolBar.transform = CGAffineTransformMakeTranslation(0,  keyboardF.origin.y - kScreenHeight);
    }];
}

- (void)setupTextWordToolBar{
    SinceToolBar *toolbar = [SinceToolBar toolBar];
    toolbar.backgroundColor = [UIColor redColor];
    toolbar.width = self.view.width;
    toolbar.height = 44;
    toolbar.y = self.view.height - toolbar.height;
    [self.view addSubview:toolbar];
    self.toolBar = toolbar;
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
}

 

监听键盘frame变化

标签:selector   code   nil   width   info   bar   cto   ext   value   

原文地址:http://www.cnblogs.com/HJiang/p/iOS.html

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