Hello. I want to raise up the uiview
elements when the keyboard appears. My code is as follows:
1. Created listeners:
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(keyboardWillShow), name: UIKeyboardWillShowNotification, object: nil) NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(keyboardWillHide), name: UIKeyboardWillHideNotification, object: nil)
2. Delete the listener:
override func viewWillDisappear(animated: Bool) { NSNotificationCenter.defaultCenter().removeObserver(self) }
3. And describe three methods:
func keyboardWillShow(notification: NSNotification) { if let userInfo = notification.userInfo { if let keyboardSize = (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() { kbHeight = keyboardSize.height self.animatedTextField(true) } } } func keyboardWillHide(notification: NSNotification) { self.animatedTextField(false) } func animatedTextField(up: Bool) { let movement = (up ? -kbHeight : kbHeight) UIView.animateWithDuration(0.3, animations: { self.view.frame = CGRectOffset(self.view.frame, 0, movement) }) }
I want to write comments on the post, click on uitextfield
and the uitextfield
appears. I am writing and sending to the database. But after I send comments to the database, the uiview
elements uiview
up two more times (progress is thin). How to fix it?