I've got a big UITextView
, nearly full screen. If I tap it, the keyboard pops up and I can edit the text. However, the longer I type, eventually the text runs down the view, behind the keyboard. I can no longer see what I'm typing.
How do you deal with this? Do you have to track the cursor position and scroll the view manually?
You need to use following code for scroll down textview according to text range(or say according to typing)
NSRange range = NSMakeRange(textView.text.length - 1, 1);
[textView scrollRangeToVisible:range];
Hope, this will help you...
I guess you have to size your UITextView as keyboard shows/hides. So the keyboard won't be over your textview. Here is the sample codes.
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)keyboardWillShow:(NSNotification *)notification
{
[UIView beginAnimations:nil context:nil];
CGRect endRect = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect newRect = YOUT_TEXT_VIEW.frame;
//Down size your text view
newRect.size.height -= endRect.size.height;
YOUT_TEXT_VIEW.frame = newRect;
[UIView commitAnimations];
}
- (void)keyboardWillHide:(NSNotification *)notification
{
... // Resize your textview when keyboard is going to hide
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With