This is the code i wrote to move the button up when the keyboard is enabled:
@IBOutlet var lastNameText: HoshiTextField!
@IBOutlet var firstNameText: HoshiTextField!
override func viewDidLoad() {
var fab = MDCFloatingButton()
fab.translatesAutoresizingMaskIntoConstraints = false
fab.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant:-30.0).isActive = true
fab.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant:-240.0).isActive = true
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name:.UIKeyboardWillShow, object: nil )
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name:.UIKeyboardWillHide, object: nil)
@objc func keyboardWillShow(notificaion: NSNotification) {
if let keyboardSize = (notificaion.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue{
//fab = UIButton(frame: CGRect(10+20, self.view.frame.size.height - keyboardSize.height - 40,80,30))
fab.frame = CGRect(x: 320, y: 350, width: 60, height: 60)
}
}
@objc func keyboardWillHide(notification: NSNotification ) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue{
fab.frame = CGRect(x: 320, y: 350, width: 65, height: 65)
}
}
Please give input.