I have a text view with a dynamic height. As the user adds or removes text the height of the text view changes.
My issue is that as the user adds text and the text view grows it disappears behind the keyboard. I have successfully moved the view when the keyboard appears so that the text view is hidden from the start but I can't seem to figure out how to keep it above the keyboard as the height changes. Any help is much appreciated!
Functions to move view when keyboard appears and disappears:
func keyboardWillShow(sender: NSNotification) {
let info: NSDictionary = sender.userInfo!
let value: NSValue = info.valueForKey(UIKeyboardFrameBeginUserInfoKey) as! NSValue
let keyboardSize: CGSize = value.CGRectValue().size
let contentInsets: UIEdgeInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height + 20, 0.0)
scrollView.contentInset = contentInsets
var aRect: CGRect = self.view.frame
aRect.size.height -= keyboardSize.height
let activeTextFieldRect: CGRect? = activeItemRect()
let activeTextFieldCentre: CGPoint? = CGPointMake(CGRectGetMidX(activeTextFieldRect!), CGRectGetMidY(activeTextFieldRect!))
if (!CGRectContainsPoint(aRect, activeTextFieldCentre!)) {
scrollView.scrollRectToVisible(activeTextFieldRect!, animated:true)
}
}
func keyboardWillHide(sender: NSNotification) {
let contentInsets: UIEdgeInsets = UIEdgeInsetsZero
scrollView.contentInset = contentInsets
}