Question

I have a UITextView that I'm trying to keep hidden from the user, except I'm using it's autocorrect interface so I can't just put it's hidden property to true.

Currently I am putting the contentOffset such that it hides the first line of text, however this does not consistently work. Sometimes it does, other times the scroll view re scrolls to where the text is partially visible. It seems arbitrary which it does, as without changing a line of code, the behavior will switch by itself after I rebuild...

I have tried turning off scrolling for the UITextView, as well as overriding the UITextView's drawRect function to not do anything, as well as changing the TextColor of the UITextView to clear color. It seems that you cannot change the alpha values of text colors so that did not work.

Any other ideas on how to achieve this? Thanks in advance.

Was it helpful?

Solution

Perhaps the UIScrollView is trying to be smart about where it is automatically scrolled to, even though you have disabled user scrolling?

You could try manipulating the contentOffset, and see if controlling that value stops the unwanted scrolling.

Another idea to help debug any unwanted scrolling activity is to add debug NSLog statements into a few of the key methods of UIScrollViewDelegate, such as scrollViewDidScroll: or scrollViewShouldScrollToTop:. If the contentOffset approach fails, this might help you understand what is going wrong, and possibly prevent it at the delegate level.

By the way, it sounds like what you're doing in general is kind of hacky. You might end up with more to-the-point answers (and cleaner code) by just asking about your true goal - maybe having your own version of spell checking?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top