zoukankan      html  css  js  c++  java
  • iOS 获取键盘相关信息

    一,在需要的地方添加监听

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

     二,响应监听方法

    - (void)onKeyboardWillShowNotification:(NSNotification*)notify {
        NSDictionary *userInfoDic = [notify userInfo];
        NSLog(@"userInfoDic = %@", userInfoDic);
        CGFloat timerval = [[userInfoDic objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
        NSValue *keyboardFrameValue = [userInfoDic objectForKey:UIKeyboardFrameEndUserInfoKey];
        CGRect keyboardFrame = [keyboardFrameValue CGRectValue];
        [UIView animateWithDuration:timerval animations:^(void){
            self.containerView.frame = CGRectMake(self.containerView.frame.origin.x, self.containerView.frame.origin.y - keyboardFrame.size.height, self.containerView.frame.size.width, self.containerView.frame.size.height);
        }];
    }
    
  • 相关阅读:
    Python之while循环
    Python之分支语句
    Python之变量
    Python开挂的吧!
    xshell 连接 ubuntu 16.04报错
    js中的script标签
    javascript中的事件学习总结
    【JAVAWEB学习笔记】04_JavaScript
    【JAVAWEB学习笔记】03_JavaScript
    【JAVAWEB学习笔记】02_HTML&CSS
  • 原文地址:https://www.cnblogs.com/shidaying/p/4414889.html
Copyright © 2011-2022 走看看