I used the following code in the view controller to update the offset of the contents of the UITextView when the keyboard is displayed:
- (void)keyboardWasShown:(NSNotification *)notification { NSDictionary *info = [notification userInfo]; CGRect keyboardRect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; UIEdgeInsets contentInsets = UIEdgeInsetsMake( 0.0, 0.0, keyboardRect.size.height, 0.0 ); self.textView.contentInset = contentInsets; self.textView.scrollIndicatorInsets = contentInsets; }
When the keyboard is displayed, manually scrolling the contents of the UITextView to the bottom of the screen, it ends just above the top of the keyboard. - [UITexView scrollRangeToVisible:], however, it seems to no longer account for the presence of the keyboard.
- In iOS 6, the text view scrolls until the specified range is displayed just above the keyboard.
- In iOS 7, visibility will now be based on the frame of the text view, and not on the insertion of content, as it was before. Thus, the view will scroll only when the range is below the frame, and then it will scroll only to get this range, visible at the bottom
Visually, this is what happens. I built a built-in search for my text view with controls to navigate between the results (similar to searching in Safari). Thus, in the text view shown here with the search results , when the user clicks the "Next" button, the blue selection will cycle through the results. When the user moves to the seventh result, the view will scroll until it becomes visible.
With the keyboard (from UISearchBar) up the same search results , when the user moves to the fifth search result, he will scroll just above the keyboard, but only in iOS 6. In iOS 7, scrolling does not happen until the transition to the seventh search result, for example, in a situation other than the keyboard, and even then it scrolls the same amount as it is visible below the bottom of the text presentation frame.
Is this a known change in iOS 7? I use auto-layout, so the next thing Iām going to try is to adjust the distance to the bottom level of the text to reduce the whole view, to avoid the problem, but I want to check if there is a way to use my existing code under iOS 7.