zoukankan      html  css  js  c++  java
  • uiviewcontroller 键盘不遮挡信息

    //添加监听事件
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    
    //监听回调
    #pragma mark - keyboard 
    - (void)keyboardWillShow:(NSNotification*)notification {
    
        CGRect frame = self.view.frame;
        frame.origin.y -= 166;
        //frame.size.height +=216;
        // Shrink view's inset by the keyboard's height, and scroll to show the text field/view being edited
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]];
        [UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]];
        self.view.frame = frame;
        [UIView commitAnimations];
    }
    
    - (void)keyboardWillHide:(NSNotification*)notification {
    
        CGRect frame = self.view.frame;
        frame.origin.y += 166;
        //frame.size.height -=216;
        //self.view移回原位置
        // Restore dimensions to prior size
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]];
        [UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]];
        self.view.frame = frame;
        [UIView commitAnimations];
    }
  • 相关阅读:
    Python 之pymysql数据库模块
    Python 之sqlite3数据库模块
    Python 之操作sqlite3
    Python 之requests网络请求模块
    Python 之os文件目录模块
    Python 之json模块
    Python 之random随机数模块
    vue.js三种安装方式
    VUE学习之计算属性computed
    vue添加背景音乐
  • 原文地址:https://www.cnblogs.com/Clin/p/3199349.html
Copyright © 2011-2022 走看看