NSNotificationCenter Swift 3.0 on keyboard show and hide

后端 未结 9 2223
日久生厌
日久生厌 2020-12-05 19:49

I am trying to run a function when the keyboard shows and disappears and have the following code:

let notificationCenter = NotificationCenter.default
notific         


        
9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 20:19

    set keyboard notification observer in

    override func viewDidLoad() {
        super.viewDidLoad()
    
        // Do any additional setup after loading the view.
        NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardNotification(notification:)), name: NSNotification.Name.UIKeyboardDidShow, object: nil)
    }
    

    and in your function handle it

    func keyboardNotification(notification: NSNotification) {
      print("keyboard displayed!!")
    }
    

    hope this will help you.

提交回复
热议问题