I am testing an iOS application using 6.1 simulator. I worked for hours to scroll my scrollView to the right position when the keyboard is visible (after the user clicks on the textView). I tried after the answer marked as correct on this page:
How to scroll UIScrollView when keyboard appears?
This is what I have:
- (void)keyboardWasShown:(NSNotification*)aNotification { NSLog(@"keyboardWasShown"); NSDictionary* info = [aNotification userInfo]; CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0); self.scrollView.contentInset = contentInsets; self.scrollView.scrollIndicatorInsets = contentInsets;

From the images above it can be seen that if the user clicks on the textView, scrollView does not scroll to the desired position (you should be able to see the text content of the textView).
The strange thing is that I manually tried to change the y scrollPoint offset to different values, but it didn't seem to affect where the window scrolls. What am I doing wrong?
Other things that may be important:
- I have auto-shutdown disabled (so the user can scroll vertically in this view).
- textView does not scroll (it changes according to its contents)
Edit
I found that if I add an offset to the contentInsets as follows:
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height+50.0, 0.0);
the view moves to the desired position. The only drawback is that there is an additional addition below:

Is there a better way to do this?
ios objective-c uiscrollview keyboard
scientiffic Sep 06 '14 at 20:36 2014-09-06 20:36
source share