tags:

views:

29

answers:

1

My scroll view scrolls down extra... what could be the possible reason? It works fine in first go but when I edit my textfield in the scrollview, it starts scrolling extra down. Any clue?

A: 

After editing the text in the TextView, you will have to update the content size of the ScrollView accordingly. For instance, if the ScrollView contains only the contents of the TextView:

[textView setText:someText];
[scrollView setContentSize:[textView contentSize]];

If the ScrollView manages more than just the TextView, you will have to update the scrollview's contentsize by doing calculations after you get the contentsize of the textview.

codelark
Can you please elaborate more on this. I have'nt worked with scrollview much. My scrollview contains 5-6 UI elements and they are ok in first go. Once I click on my textfield, I am doing this: [aBaseScrollView setContentInset:UIEdgeInsetsMake(0.0f, 0.0f, aKeyBoardheight, 0.0f)]; and [aBaseScrollView scrollRectToVisible:aTextFrame animated:YES];
Abhinav
Basically anytime the size of the contents of the ScrollView change, you need to update the ScrollView's contentSize. How you do this is dependent on several factors like which components will be resized and in what dimension, etc. For instance if you have a bunch of buttons that add up to X pixels, then a textview below them, and the size of the textview's content changes due to input, you take the contentsize of the textview after you set the new text, add X to it's height, and set that as the contentSize for the ScrollView.
codelark
Got it... One doubt... How would I set the content size if more than 1 of my elements are being changes. Lets say, my scrollview contains 5 elements out of which after server hit, I modified 3 fields in my scrollview inside my server fetch response delegate. Where should I update the content size of my scrollview and how would I tell it to accommodate new size changes. Please explain through some code example.
Abhinav