Skip to content
APE
  • 首页

Category Swift

  • 首页   /  前端 iOS
  • 分类归档: "Swift"
  • ( 页面2 )
iOS, Swift, 前端 5 月 17,2019

Swift5监听软键盘弹出、隐藏事件

代码示例

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    //注册键盘出现通知
    NotificationCenter.default.addObserver(self, selector: #selector(show(node:)), name:  UIResponder.keyboardWillShowNotification, object: nil)
        
    //注册键盘隐藏通知
    NotificationCenter.default.addObserver(self, selector: #selector(hide(node:)), name:  UIResponder.keyboardWillHideNotification, object: nil)
}

override func viewWillDisappear(_ animated: Bool) {
    super .viewWillDisappear(animated)
    //注销键盘出现通知
    NotificationCenter.default.removeObserver(self,name: UIResponder.keyboardWillShowNotification,object: nil)
    //注销键盘隐藏通知
    NotificationCenter.default.removeObserver(self,name: UIResponder.keyboardWillHideNotification,object: nil)
}

@objc private func show(node : Notification){
    print("软键盘弹起")
}
    
@objc private func hide(node : Notification){
    print("软键盘隐藏")
}

添加软键盘监听

显示
NotificationCenter.default.addObserver(self, selector: #selector(show(node:)), name:  UIResponder.keyboardWillShowNotification, object: nil)

事件处理

@objc private func show(node : Notification {
   print("软键盘弹起")
}
隐藏
NotificationCenter.default.addObserver(self, selector: #selector(hide(node:)), name:  UIResponder.keyboardWillHideNotification, object: nil)

事件处理

@objc private func hide(node : Notification){
   print("软键盘隐藏")
}

源码下载

Swift5监听软键盘弹出、隐藏事件(源码)Download
作者 peng

上一 1 2

Just For You - 李嘉格,李唯枫

http://cdn.ape.ren/wp-content/uploads/2020/09/1600942088-Just-For-You-李嘉格李唯枫.mp3

近期文章

  • logstash 配置jdbc数据源 output 到 Elasticsearch 2022年11月24日
  • MySQL SQL性能分析Explain执行计划 2020年12月11日
  • CentOS 7安装MySQL8.0配置主从复制 2020年12月8日
  • Nginx配置二级目录访问ThinkPhp 2020年1月20日
  • Android Gradle更换为阿里源 2019年11月26日
  • Swift5 iOS 集成支付宝支付 2019年10月27日
  • Swift5 iOS 集成百度语音识别 2019年7月10日
  • Swift5 UISwitch基本使用方法 2019年5月18日
  • Swift5 监听TextField/TextView软键盘return按钮点击事件 2019年5月17日
  • Swift5监听软键盘弹出、隐藏事件 2019年5月17日
  • Android图像加载之Picasso 2019年5月14日

近期评论

    归档

    • 2022 年 11 月 (1)
    • 2020 年 12 月 (2)
    • 2020 年 1 月 (1)
    • 2019 年 11 月 (1)
    • 2019 年 10 月 (1)
    • 2019 年 7 月 (1)
    • 2019 年 5 月 (4)

    分类

    • Android (2)
    • Elasticsearch (1)
    • iOS (5)
    • logstash (1)
    • MySQL (3)
    • Nginx (1)
    • Swift (5)
    • 前端 (5)

    标签

    Alipay Android CentOS 7 Elasticsearch Gradle iOS logstash MySQL MySQL8.0 Nginx PHP SQL优化 Swift ThinkPHP 支付宝 语音识别

    其他操作

    • 登录
    • 条目 feed
    • 评论 feed
    • WordPress.org

    渝ICP备19006962号-1
    All Rights Reserved by BusiProf. Designed and Developed by WordPress Theme.