弹出键盘时,底部按钮一起动

//viewWillAppear

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(true)
        NotificationCenter.default.addObserver(self, selector: #selector(keyBoardChange(notification:)), name:NSNotification.Name.UIKeyboardDidChangeFrame, object: nil)
        //  NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(keyBoardDidHide(_:)), name:UIKeyboardDidHideNotification, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(keyBoardWillShow(notification:)), name:NSNotification.Name.UIKeyboardWillShow, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(keyBoardWillHide(notification:)), name:NSNotification.Name.UIKeyboardWillHide, object: nil)
    }
//MARK:键盘悬浮处理
    func keyBoardChange(notification :NSNotification){
        
    }
    
    
    func keyBoardWillShow(notification :NSNotification){
        
        // print("键盘将要显示")
        let dict:NSDictionary = notification.userInfo! as NSDictionary
        let aValue = dict.object(forKey: UIKeyboardFrameEndUserInfoKey)
        let keyboardRect = (aValue! as AnyObject).cgRectValue
        let keyHeight =  keyboardRect?.size.height
        self.saveBtn.frame = CGRect(x: 0, y: SCREEN_HEIGHT-48-keyHeight!, width: SCREEN_WIDTH, height: 48)
    }
    
    func keyBoardWillHide(notification :NSNotification){
        saveBtn.frame = CGRect(x: 0, y: XY_SCREEN_HEIGHT - 48 , width: XY_SCREEN_WIDTH, height: 48)
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        NotificationCenter.default.removeObserver(self)
        
    }```
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容