Note that there are some explanatory texts on larger screens.

plurals
  1. POUIScrollView scrolling to bottom when UITextField text changes
    primarykey
    data
    text
    <p>As it is set up now, I have two UITextViews inside of a UIScrollView. The point of this is that the UITextViews themselves don't scroll, they just get larger (their contentsize) as more text is added. The UIScrollView handles all of the scrolling up and down of the view regardless of how much text there is (think similar to Mail.app where the subject view is above the message view, etc). That said, I've ran into a problem now. When I programmatically add text to my UITextView (in this code, bodyText), the UIScrollView automatically scrolls to the bottom for some reason.</p> <p>To add the text I just do: </p> <pre><code>NSRange selectedRange = [bodyText selectedRange]; NSString *selectedText = [bodyText.text substringWithRange:selectedRange]; bodyText.text = [bodyText.text stringByReplacingCharactersInRange:selectedRange withString:[NSString stringWithFormat:@"&lt;b&gt;%@&lt;/b&gt;", selectedText]]; </code></pre> <p>So, for instance, if I had 2000 pixels vertically of text and was currently scrolled to position 400 and then added text somewhere around there, the UIScrollView would then go all the way down to 2000.</p> <p>I've tried to stop it via subclassing UISCrollView and overriding -setContentOffset, but that freezes all scrolling then.</p> <p>My question is, why does it scroll all the way to the bottom in the first place? The text is added when the user clicks a button somewhere else on the screen, and the scrolling has nothing to do with any finger drags or anything.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload