In my extension I put the control for the keyboard notification in this way
protocol KeyboardSpaceProtocol {
func addObservers()
func removeObservers()
func keyboardWillShow(notification:NSNotification) -> CGFloat
}
extension UIView: KeyboardSpaceProtocol {
func addObservers() {
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(keyboardWillShow), name: UIKeyboardWillShowNotification, object: nil)
}
func removeObservers() {
NSNotificationCenter.defaultCenter().removeObserver(self)
}
func keyboardWillShow(notification:NSNotification) -> CGFloat {
let userInfo:NSDictionary = notification.userInfo!
let keyboardFrame:NSValue = userInfo.valueForKey(UIKeyboardFrameEndUserInfoKey) as! NSValue
let keyboardRectangle = keyboardFrame.CGRectValue()
return keyboardRectangle.height
}
}
now I want update a CGFloat value (keyboardheight
) in my UIView class... how can I in my view controller? I don't know when the keyboard go out and how to update my value.
Any suggestions?