• 键盘弹起


    - (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;
    }
  • 相关阅读:
    VC 中 C2275问题解决
    MIPS指令学习
    《高效人士的116个IT秘诀》读书笔记
    Mercurial入门学习
    foobar 插件安装
    五笔输入法的学习记录
    AutoHotKey入门使用
    windows shell
    CSPS 2021霜降记
    ubunru下jdk安装
  • 原文地址:https://www.cnblogs.com/menglingxu/p/6118711.html
Copyright © 2020-2023  润新知