Reputation: 27191
I have set constraints to the text view as on image below:
But as you can see on the simulator the contentOffset is different for text view under ARTIST NAME label. Seems like text view tries to show text from the bottom then from top at first:
I want to try to resolve this issue without any code, but I have added this method that scrolls text view back to the top:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.theTextView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
}
When I debug code and print out text view before line [self.theTextView scrollRectToVisible:CGRectMake(0,0,1,1) animated:NO]
the contentOffset of text view is 0, 144.5:
(lldb) po self.theTextView
<UITextView: 0x7d26ac00; frame = (3 423; 153 90); text = 'Lorem ipsum dolor sit er ...'; clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7bbbdf30>; layer = <CALayer: 0x7bbbd540>; contentOffset: {0, 144.5}; contentSize: {153, 243}>
After [self.theTextView scrollRectToVisible:CGRectMake(0,0,1,1) animated:NO]
contentOffset is 0, 0:
(lldb) po self.theTextView
<UITextView: 0x7d26ac00; frame = (3 423; 153 90); text = 'Lorem ipsum dolor sit er ...'; clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7bbbdf30>; layer = <CALayer: 0x7bbbd540>; contentOffset: {0, 0}; contentSize: {153, 243}>
But I can figure out why constraints bring some issues with content offset. And why at start text is shifted. Without any constraints text view displays "Lorem ipsum" as a first line, but with constraint it shows "nulla pariatur..." as you can see on image above as full visible line the line above is cut off at all.
Upvotes: 0
Views: 292
Reputation: 1541
In layoutSubviews if UIView and in viewDidLayoutSubview ad the below line:
[textview setContentOffset:CGPointMake(0,0)];
This worked for me.
Upvotes: 1