How to dismiss keyboard on iPhone 6 after rotation

529 views Asked by At

I am trying to dismiss the keyboard when a uisearchdisplaycontroller is no longer active on the iPhone 6 plus. I can end editing of the search bar but the keyboard stays active on the screen. I have tried many ways, but here is my current code.

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    if(searchDisplayController!.active) {
        self.view.endEditing(true)
        self.searchDisplayController!.active = false
    }
}

Any ideas?

1

There are 1 answers

2
bllakjakk On BEST ANSWER

Try using below function for detecting rotation:

override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
}

Also use resignFirstResponder for hiding the keyboard.