• iOS监听键盘事件


    #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];
        
    }
  • 相关阅读:
    Nexus入门指南(图文)[转]
    java注解[转]
    JS设置IE可信站点及ActiveX设置
    ExtJS 4 树
    SQL大全
    基于Spring aop 和JAVA注解方式添加日志
    Excle自动增长序号
    VS 生成后事件
    Oracle命令分解之正则表达式搜索(一)
    Oracle命令分解之……SOUNDEX
  • 原文地址:https://www.cnblogs.com/songxing10000/p/4944031.html
Copyright © 2020-2023  润新知