zoukankan      html  css  js  c++  java
  • iOS 键盘的监听 调整view的位置

    iOS在处理键盘的出现和消失时需要监听UIKeyboardWillChangeFrameNotifications/UIKeyboardDidHideNotifications

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
    //添加监听 键盘消失
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDown) name:UIKeyboardDidHideNotification object:nil];
    
    //添加监听 键盘出现
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
    }
    
    
    - (void)keyboardWillChangeFrame:(NSNotification *)noti{
    
    //取出键盘动画的时间(根据userInfo的key-UIKeyboardAnimationDurationUserInfoKey)
    
        CGFloat duration = [noti.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
        
    
    
     //取得键盘最后的frame(根据userInfo的key----UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 227}, {320, 253}}";)
    
        CGRect keyboardFrame = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
      
    //处理键盘出现的是页面的变化。。。。。。
    }
    
    
    - (void)keyboardDown
    {
        //处理键盘消失是页面的变化 。。。。。。
    }
  • 相关阅读:
    iOS内存管理机制
    iOS开发之XML和JSON数据解析
    Ubuntu小点汇总,更新中...
    Android与服务器的简单通讯
    Gedit乱码问题
    Eclipse软件问题-方案积累
    开放接口使用积累
    定制知识积累
    Android小代码-技巧积累
    Android初学点滴积累(操作篇)
  • 原文地址:https://www.cnblogs.com/carlos-mm/p/5978278.html
Copyright © 2011-2022 走看看