• iOS——UIKeyboardWillShowNotification 监听键盘高度变化


    - (void)viewDidLoad {

        [super viewDidLoad];

        UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 100, 50)];

        textField.backgroundColor = [UIColor blueColor];

        [self.view addSubview:textField];

    //出现键盘

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

     //键盘隐藏

     [[NSNotificationCenter defaultCenter] addObserver:self 

                                               selector:@selector(keyboardWillHidden:) 

                                                   name:UIKeyboardWillHideNotification 

                                                 object:self.view.window];

        };

     

    -(void)keyboardWillShow:(NSNotification*)notification{

        NSDictionary*info=[notification userInfo];

        CGSize kbSize=[[info objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size;

        NSLog(@"keyboard changed, keyboard width = %f, height = %f",

              kbSize.width,kbSize.height);

        //在这里调整UI位置

    }

      //键盘将要消失

    -(void)keyboardWillHidden:(NSNotification*)notification

    {

     

     NSDictionary*info=[notification userInfo];

        CGSize kbSize=[[info objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size;

        NSLog(@"keyboard changed, keyboard width = %f, height = %f",

              kbSize.width,kbSize.height);

    }

     

  • 相关阅读:
    【3】hexo+github搭建个人博客的主题配置
    【2】hexo+github搭建个人博客的简单使用
    每日思考(2020/05/06)
    每日思考(2020/05/05)
    每日思考(2020/03/27)
    文件和异常
    每日思考(2020/03/24)
    图形用户界面和游戏开发
    每日思考(2020/03/19)
    面向对象进阶
  • 原文地址:https://www.cnblogs.com/AlienY/p/4539931.html
Copyright © 2020-2023  润新知