iphone 始终隐藏 UITextView 中的一些文本
我有一个 UITextView,我试图对用户隐藏它,除非我使用它的自动更正界面,所以我不能只是将它的隐藏属性设置为 true。
目前,我放置 contentOffset 使其隐藏文本的第一行,但这并不总是有效。 有时确实如此,有时滚动视图会重新滚动到文本部分可见的位置。 它似乎是任意的,因为在不更改一行代码的情况下,行为会在我重建后自行切换...
我尝试关闭 UITextView 的滚动,以及覆盖 UITextView 的 drawRect 函数以不执行任何操作,以及将 UITextView 的 TextColor 更改为透明颜色。 似乎您无法更改文本颜色的 alpha 值,因此不起作用。
关于如何实现这一目标还有其他想法吗? 提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许 UIScrollView 试图智能地了解自动滚动到的位置,即使您已禁用用户滚动?
您可以尝试操作
contentOffset
,并查看控制该值是否会阻止不需要的滚动。帮助调试任何不需要的滚动活动的另一个想法是将调试
NSLog
语句添加到UIScrollViewDelegate
的几个关键方法中,例如scrollViewDidScroll:
或scrollViewShouldScrollToTop:
。 如果contentOffset
方法失败,这可能会帮助您了解出了什么问题,并可能在委托级别阻止它。顺便说一句,听起来你所做的事情总体来说有点hacky。 通过询问您的真正目标,您可能最终会得到更切中要点的答案(和更清晰的代码) - 也许有您自己的拼写检查版本?
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 ofUIScrollViewDelegate
, such asscrollViewDidScroll:
orscrollViewShouldScrollToTop:
. If thecontentOffset
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?