Skip to content
This repository has been archived by the owner on Jun 17, 2023. It is now read-only.

Commit

Permalink
Handle keyboard frame on iPad
Browse files Browse the repository at this point in the history
  • Loading branch information
Amir Khorsandi committed Jul 5, 2020
1 parent 89027fd commit d7c52c4
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class LayoutDesignerViewController: UIViewController, ViewModelBased, NibBased {
super.viewDidLoad()
configureViews()
setOptionsList()
registerKeyboardNotifications()
}

deinit {
NotificationCenter.default.removeObserver(self)
}


Expand Down Expand Up @@ -132,6 +137,27 @@ class LayoutDesignerViewController: UIViewController, ViewModelBased, NibBased {
optionsTableView.optionViewModels = viewModel.optionViewModels
}

private func registerKeyboardNotifications() {
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(adjustForKeyboard), name: UIResponder.keyboardWillHideNotification, object: nil)
notificationCenter.addObserver(self, selector: #selector(adjustForKeyboard), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
}

@objc private func adjustForKeyboard(notification: Notification) {
guard let keyboardValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else { return }

let keyboardScreenEndFrame = keyboardValue.cgRectValue
let keyboardViewEndFrame = view.convert(keyboardScreenEndFrame, from: view.window)
var contentInset = optionsTableView.contentInset

if keyboardViewEndFrame.minY < optionsTableView.frame.maxY {
contentInset.bottom = optionsTableView.frame.maxY - keyboardViewEndFrame.minY - 8
} else {
contentInset.bottom = 8
}
optionsTableView.contentInset = contentInset
}

}


Expand Down

0 comments on commit d7c52c4

Please sign in to comment.