Hi guys I am making a notes app and I ran into a big problem. I am using a UITextView as the notepad. When the keyboard comes up it blocks some of the text in the UITextView. I have a input accessory view on the UITextView. I tried to find the answer in the internet and can not find a good answer.Any way to fix it? Here is a picture:
Asked
Active
Viewed 1,564 times
0
-
http://stackoverflow.com/questions/13701478/how-to-make-an-uitextview-scrollable-when-the-keyboard-appears/13702111#13702111 – Rajneesh071 Aug 06 '13 at 06:00
3 Answers
1
You might want to look at modifying the UITextView's contentOffset and contentInset. UITextField is a UIScrollView subclass after all.

james_womack
- 10,028
- 6
- 55
- 74
1
I decided to subtract the UITextView height by the keyboard height:
NSDictionary* info = [notification userInfo];
kbSIZE = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
CGRect newTextViewFrame = self.notesTextView.frame;
newTextViewFrame.size.height -= kbSIZE.size.height;
newTextViewFrame.size.height += self.notesTextView.inputAccessoryView.frame.size.height;
self.notesTextView.frame = newTextViewFrame;

Abdullah Shafique
- 6,878
- 8
- 35
- 70
-
here is same thing i did in past http://stackoverflow.com/questions/13701478/how-to-make-an-uitextview-scrollable-when-the-keyboard-appears/13702111#13702111 – Rajneesh071 Aug 06 '13 at 06:00
-
3I would advise against this as the keyboard in iOS 7 is translucent. You need to be able to see the content scroll under the keyboard. – Luke Aug 07 '13 at 22:13
1
You have to set contentInset
and scrollIndicatorInsets
to the UIEdgeInsets
of the keyboard height. The contentInset
value makes the scrolling height taller, but allows you to still scroll content under the keyboard. The scrollIndicatorInsets
makes the scroll indicators stop at the bottom of the keyboard.
- (void)viewDidLoad
{
[super 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
{
NSDictionary *info = [notification userInfo];
CGSize kbSize = [info[UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
self.textView.contentInset = contentInsets;
self.textView.scrollIndicatorInsets = contentInsets;
}
- (void)keyboardWillHide:(NSNotification *)aNotification
{
self.textView.contentInset = UIEdgeInsetsZero;
self.textView.scrollIndicatorInsets = UIEdgeInsetsZero;
}

Luke
- 13,678
- 7
- 45
- 79