zoukankan      html  css  js  c++  java
  • 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);

    }

     

  • 相关阅读:
    推荐下自己的开源框架:DataMapFramework
    真的能无师自通吗?JAVA学习指导系列
    再回首,工作的第一个十年
    2个DataSet中的数据传递问题,请高手们多多指教。
    数据结构小结
    CDQZ_Training 2012524 词编码
    PowerDesigner显示Comment注释
    DDD基本元素
    使用FluorineFx.NET更新FMS中的SharedObject
    如何取消页面缓存
  • 原文地址:https://www.cnblogs.com/AlienY/p/4539931.html
Copyright © 2011-2022 走看看