zoukankan      html  css  js  c++  java
  • ios 监控键盘状态

    增加键盘显示和隐藏事件监听

    NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
            
    NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
    
    @objc func keyboardWillShow(notification:Notification){
            let userinfo:Dictionary = notification.userInfo!
            let frame = (userinfo[UIResponder.keyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
            UIView.animate(withDuration: 0.4, animations: {
                self.view.frame.origin.y = 0 - frame.height
            })
        }
        
        @objc func keyboardWillHide(notification:Notification){
            UIView.animate(withDuration: 0.4, animations: {
                self.view.frame.origin.y = 0
            })
        }
    

      删除事件监听

    NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillShowNotification, object: nil)
            NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
    

      

  • 相关阅读:
    node下运行ts
    npm的一些基本配置设置
    windws 安装jdk
    java jdbc连接mysql
    struts2+jquery 实现ajax登陆
    struts2 零配置
    java 生成UUID
    ubuntu 换源
    ubuntu下安装redis
    安装 vsftpd
  • 原文地址:https://www.cnblogs.com/rchao/p/12000606.html
Copyright © 2011-2022 走看看