swift keyboard view adjustment
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
let notificationCenter = NSNotificationCenter.defaultCenter()
notificationCenter.addObserver(self, selector: #selector(ParentalConrolViewController.keyboardWillShow(_:)), name: UIKeyboardWillShowNotification, object: nil)
notificationCenter.addObserver(self, selector: #selector(ParentalConrolViewController.keyboardWillHide(_:)), name: UIKeyboardWillHideNotification, object: nil)
}
override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)
let notificationCenter = NSNotificationCenter.defaultCenter()
notificationCenter.removeObserver(self, name: UIKeyboardWillShowNotification, object: nil)
notificationCenter.removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)
}
func keyboardWillShow(notification: NSNotification) {
let userInfo = notification.userInfo!
let keyboardHeight = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue().height
UIView.transitionWithView(self.view, duration:0.3,
options: UIViewAnimationOptions.CurveEaseInOut,
animations: {
self.view.frame.origin.y = -yShift
}, completion: nil)
}
func keyboardWillHide(notification: NSNotification) {
UIView.transitionWithView(self.view, duration: 0.325, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
self.view.frame.origin.y = 0
}, completion: nil)
}