2

I have a UITextView in my app. I need to change it's content offset dynamically every time a new string is appended. The code bellow works fine on iOS 6 and earlier versions, but not on iOS 7.

TextViewText.text = [TextViewText.text stringByReplacingCharactersInRange:RecentWordRange withString:string];
   newStringLen = string.length;
   [TextViewText setSelectedRange: NSMakeRange(RecentWordRange.location+string.length, 0)];
   [TextViewText setContentOffset: CGPointMake(0,0) animated:NO];
   [TextViewText setContentOffset:contentOffset animated:YES];

what is change in IOS7 for setContentOffset?

Shinning River
  • 813
  • 1
  • 10
  • 23
  • what is the variable contentOffset containing? – John Riselvato Oct 11 '13 at 19:09
  • contentOffset = TextViewText.contentOffset; – Shinning River Oct 11 '13 at 19:22
  • This is an iOS 7 bug. My workaround is here and it works: http://stackoverflow.com/questions/19124037/scroll-to-bottom-of-uitextview-erratic-in-ios-7-with-many-updates/19339716#19339716 – RawMean Oct 12 '13 at 22:23
  • This is an iOS 7 bug. My workaround is here: http://stackoverflow.com/questions/19124037/scroll-to-bottom-of-uitextview-erratic-in-ios-7-with-many-updates/19339716#19339716 – RawMean Oct 12 '13 at 22:24

2 Answers2

2

Use UITextView's textContainerInset for what would be insets, and use (UIEdgeInsets)contentInset for what would be (CGPoint)contentOffset.

No idea why someone decided this was the best way to handle UITextView offsetting, but this is working for me.

Also note that there is a strange bug that doesn't accept insets on the textView unless there is a right and left offset. So make sure left/right UIEdgeInsets are greater than 1.

user
  • 3,388
  • 7
  • 33
  • 67
0

Recently I resolved a similar problem in iOS 8. I Replaced text in the text view and it jumped around. Using the UITextRange related method helped.

UITextRange *RecentWordRange = TextViewText.selectedTextRange;
[TextViewText replaceRange:RecentWordRange withText:string];
Kirill Fuchs
  • 13,446
  • 4
  • 42
  • 72
maudy2
  • 1