I have a text view at the bottom of the view controller. When the text view becomes first responder, the keyboard appears, but it covers the text view. How do I make the text view visible?
You can set frame of set content offset by setting y origin.
#pragma mark - Textview delegate
- (void)textViewDidBeginEditing:(UITextView *)textView
{
[UIView animateWithDuration:0.3 animations:^{
//Either set content offset or frame
//textView.frame = CGRectMake(textView.frame.origin.x, originY, textView.frame.size.width, textView.frame.size.height);
textView.contentOffset = CGPointMake(textView.frame.origin.x, originY);
} completion:^(BOOL finished) {
}];
}
And finally, when you resign first responder, then again reset it to the original position.
1 Like
Also, you can try moving your view up whenever the keyboard showing notification is posted.
NotificationCenter.default.addObserver(self,
selector: #selector(self.moveViewUp(notification:)),
name: NSNotification.Name.UIKeyboardWillShow,
object: nil)
func moveViewUp(notification: NSNotification) {
let userInfo = notification.userInfo
let keyboardSize = userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue
let keyboardHeight = keyboardSize.cgRectValue.height
}
And of course, you just bring the view back down when the opposite notification (UIKeyboardWillShow) is posted.