I want to get a display/hide status of the iOS keyboard.

Asked 2 years ago, Updated 2 years ago, 42 views

In iOS 10.11, I want to get my keyboard showing and hiding.

I'd like to separate the processing between when the keyboard is displayed and when it is hidden.

swift ios

2022-09-30 19:50

1 Answers

// Prepare variables
varisShown=false

// Configure monitoring in viewDidLoad, etc.
NotificationCenter.default.addObserver(self,selector:#selector(keyboardDidAppear), name:UIResponder.keyboardDidShowNotification, object:nil)
NotificationCenter.default.addObserver(self,selector:#selector(keyboardDidDisappear), name:UIResponder.keyboardDidHideNotification, object:nil)

switch flags
@objc func keyboardDidAppear(){
    isShown = true
}
@objc func keyboardDidDisappear(){
    isShown = false
}

if isShown{
    // When the keyboard is displayed
} else{
    // the time when a person is hiding
}


2022-09-30 19:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.