UITextView inside UIScrollView scroll task

I am experiencing something that is considered a mistake in my situation. This is probably not a mistake, but a function;).

Here is my case:

I am loading a UIScrollView with my content. Part of my content is loaded asynchrone after the view is already loaded. This works great and no problem. However, some of these controls are UITextView controls. Once I set the contents (text property) of these controls after viewDidLoad, my UIScrollView scrolls to the last set UITextView. I want to prevent this and want the UIScrollView to maintain its top scroll position.

In short: If I set the Text property in the viewDidLoad method, scrolling is not performed. If I set the Text property to a UITextView after the viewDidLoad method (because I load data asynchronously), the UIScrollView will scroll to the last set UITextView. I want to prevent this scroll.

How do I achieve this? I have the feeling that this is just a property that is configured incorrectly, but I cannot find it.

Thanks in advance.

EDIT:

I tried setting the scrollEnabled property to NO before setting the values ​​to YES, but this did not affect. ScrollView will still scroll when the text property of UITextView is set.

+7
objective-c iphone cocoa-touch uitextview uiscrollview
source share
3 answers

I fixed the workaround issue:

I set the scroll content size to something small, such as 320 x 300 or whatever the scrollview frame height is, and then did my job, and then returned the content size to normal.

This prevents scrolling during data loading and allows it as soon as the download is complete.

+6
source share

This will not change the scroll problem, but it may make it β€œhidden” to the user:

yourTextView.text = @"Eat more bananas!"; yourScrollView.contentOffset = CGPointMake(0.0, 0.0); 

Some pieces of code will help solve the problem more specifically.

EDIT: Or try adding UITextViews to UIView, and then add UIView to UIScrollView. Make sure the UIScrollView contentSize is the same size as the UIView.

+5
source share

This worked for me too: p, but I needed to set the height to something less than 300 (in my case, I just used 10).

Basically, the idea is to make the text view not part of the visible area of ​​the UIScrollView as you change the text of the UITextView.

+1
source share

All Articles