• 键盘弹起


    - (void)viewWillAppear:(BOOL)animated
    {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    }
    
    // 键盘显示
    - (void)keyboardWillShow:(NSNotification *)notification
    {
        CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
        CGFloat height = keyboardFrame.origin.y;
        
        // 计算视图需要移动的距离
        CGFloat space = self.imageView.frame.origin.y + self.imageView.frame.size.height;
        
        // 得出键盘距离输入框的间距
        CGFloat trsformY = height - space;
        
        if (trsformY < 0) {
            CGRect frame = self.view.frame;
            frame.origin.y = trsformY;
            self.view.frame = frame;
        }
        
    }
    
    // 键盘隐藏
    - (void)keyboardWillHide:(NSNotification *)notification
    {
        CGRect frame = self.view.frame;
        frame.origin.y = 64;
        self.view.frame = frame;
    }
  • 相关阅读:
    面向对象--封装
    面向对象--多态
    面向对象编程
    类的特殊成员
    新式类 VS 经典类
    python类的继承
    python析构函数
    类的公有属性
    (转)JAVA AJAX教程第二章-JAVASCRIPT基础知识
    (转)JAVA AJAX教程第一章-初始AJAX
  • 原文地址:https://www.cnblogs.com/menglingxu/p/6118711.html
Copyright © 2020-2023  润新知