0

Hi I have UITextView that I want it to make its height right above the keyboard. I am making a notes app and I need to bring the UITextView up so it scroll easily.Here is the code:

CGRect keyboardBounds = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect frame = self.notesTextView.frame;
CGFloat height = self.notesTextView.frame.size.height;
height = frame.size.height;
frame.size.height -= keyboardBounds.size.height;
self.notesTextView.frame = frame;

However the screen turns out like this: enter image description here

Abdullah Shafique
  • 6,878
  • 8
  • 35
  • 70

2 Answers2

2

Here's the answer you need: https://stackoverflow.com/a/1127025/189804

Doing this right is hard but essential. Don't forget to use all the information in the info dictionary passed to the keyboard notification, You need to read the height of the emerging keyboard rather than hard-coding a value, you need to get the animation duration so you can rearrange your views with the same animation duration and you also need to respond to events while editing - imagine that a user begins editing, then decides to connect a bluetooth keyboard to make the editing task easier, or they begin editing with the keyboard connected and then the keyboard battery quits...

Community
  • 1
  • 1
Adam Eberbach
  • 12,309
  • 6
  • 62
  • 114
1

You need to resize the scroll view. Don't touch the textview's frame ever (unless you make a subclass).

CGRect frame = self.textView.enclosingScrollView.frame;
frame.size.height = 42;
self.textView.enclosingScrollView.frame = newFrame;
Abhi Beckert
  • 32,787
  • 12
  • 83
  • 110