UITextView 中的文本不会显示在 UIScrollView 中
我想要一个带有一组子视图的 UIScrollView,其中每个子视图都有一个带有不同文本的 UITextView。 对于此任务,我修改了苹果“iphone 开发中心”的 PageControl
示例,以便将其添加到用于生成子视图的简单 UITextView
视图的滚动视图。 当我运行应用程序(在模拟器和手机上)时,看不到任何文本,但如果我激活“用户交互”并单击它,文本就会神奇地出现(以及键盘)。
有没有人有解决方案或在 UIScrollView
内使用 UITextView
取得任何进展? 谢谢。
I want to have a UIScrollView
with a set of subviews where each of these subviews has a UITextView
with a different text. For this task, I have modified the PageControl
example from the apple "iphone dev center" in order to add it a simple UITextView
to the view which is used to generate the subviews of the scroll view. When I run the app (both on the simulator and the phone), NO Text is seen but if i activate the "user interaction" and click on it, the text magically appears (as well as the keyboard).
Does anyone has a solution or made any progress with UITextView
inside a UIScrollView
? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
它通过将文本值分配放入 scrollViewDidScroll 方法中来对我起作用。
示例片段:
SAMPLE.h
注释:
请记住:不要忘记 UIScrollViewDelegate 协议。
SAMPLE.m
评论:
我显然已经使用示例命名和值调整了源代码片段。 希望没有错别字。 但是,代码还包含文本所需框架高度的计算,以防文本的值可能发生变化,因此实际上需要不同的框架大小。
将实际的文本值分配到scrollViewDidScroll方法中对我来说很有效,在滚动等过程中没有任何类型的闪烁(到目前为止仅在iPhone模拟器中进行了测试)。
希望有帮助。 当然,我愿意接受任何建设性的反馈、改进建议,甚至其他解决此问题的方法。
it works for me by placing the text value assignment into the scrollViewDidScroll method.
Sample snippets:
SAMPLE.h
Comment:
Just to remember: don't forget the UIScrollViewDelegate protocol.
SAMPLE.m
Comment:
I have adjusted the source code snippet with sample namings and values obviously. Hopefully there is no typo. However, the code contains also the calculation of the required frame height for the text, in case the text's value can change and therefore would require different frame sizes actually.
Placing the actual text value assignment into the scrollViewDidScroll method worked for me without any kind of flashing during scrolling etc. (so far only tested in iPhone Simulator).
Hope that helps. Of course I am open for any constructive feedback, improvement proposals or even other ways to solve this isuse.
我对这个问题的解决方案是不同的:只有当我将 UIScrollView 的属性“Autoresize Subviews”设置为关闭时,它才起作用。
My solution to this problem was different: It only worked when I set the property "Autoresize Subviews” of the UIScrollView to off.
问题很可能出在下一个
UIScrollViews
上。我认为存在三种解决方案:
userInteractionEnabled
。UILabel
而不是UITextView
(UILabel
不是UIScrollView
的子类)UITextView
。The problem is likely to be the nexted
UIScrollViews
.I think there are three solutions:
userInteractionEnabled
as the various controls are selected.UILabel
instead of aUITextView
(UILabel
is not a subclass ofUIScrollView
)UITextView
.您可能会遇到 UITextView 从屏幕外滚动到屏幕上区域时无法正确更新的问题。
检查本页的“屏幕外 UITextView 未正确更新”部分: UIScrollView 中的多个虚拟页面
我使用的解决方案是当滚动视图开始出现在屏幕上时强制重新绘制滚动视图。 这完全是一个麻烦,但确实解决了问题。
You may be suffering from the problem where UITextView's don't update properly when they are scrolled from an offscreen to an onscreen area.
Check the "Offscreen UITextViews don't update correctly" section of this page: Multiple Virtual Pages in a UIScrollView
The solution I used was to force a redraw of scroll views when they begin to appear onscreen. This is a complete nuisance but does fix the problem.
我解决了强制“假”滚动的问题:
I resolved the problem forcing a "fake" scroll:
我认为问题源于
UITextView
是UIScrollView
的子类,因此基本上将滚动视图嵌入到UIScrollViews
中。 即使文本显示正确,您也会遇到可用性问题,因为永远不清楚手指滑动是否应该滚动外部视图或文本视图。是的,Safari 确实做到了这一点,但它必须这样做,而且这并不是使用 Safari 中最令人愉快的部分。
我认为这是困难表明你正在对抗系统的时候之一。 我强烈建议回去重新考虑用户界面。
I think the problem stems from the fact that
UITextView
is a subclass ofUIScrollView
, so you basically have scroll views embedded withinUIScrollViews
. Even if the text displayed properly, you would have usability problems, as it would never be clear if a finger swipe was supposed to scroll the outer view or the text view.Yeah, Safari sort of does this, but it has to, and it's not the most pleasant part of using Safari.
I think this is one of those times where the difficulty indicates you are working against the system. I strongly recommend going back and re-thinking the UI.