首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Swift3.0 - 键盘相关

  • 键盘出现和消失获取键盘的相关信息 注册通知
代码语言:javascript
复制
 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)


  //  触发时间
 func keyBoardWillShow(_ notification: Notification){
     guard let frame = notification.userInfo?[UIKeyboardFrameEndUserInfoKey] else{
        return
    }
    let y = (frame as! NSValue).cgRectValue.origin.y
  }

提示:

notification.userInfo?[UIKeyboardFrameEndUserInfoKey] 获取的值为为NSValue 类型,所以需要稍微转一下

下一篇
举报
领券