添加文本时,如何使带有 UITextView 子视图的 UIScrollView 不滚动?

问题描述:

我有一个 UIScrollView,它有一个子视图 UITextView.当我通过代码向 UITextView 添加文本时,视图滚动到最后一行.当我通过代码向 UITextView 添加文本时,我希望视图不滚动.谁能帮我解决这个问题?

I have a UIScrollView which has a subview UITextView. When I added text to UITextView by code, the view is scrolling to the last line. I want the view not to scroll when I add text to UITextView by code. Anyone can help me fix the problem?

我终于可以解决我的问题了.

Finally I can fix my problem.

我们只是在更改 UITextView 中的文本之前将 UITextView 中的 setScrollEnabled 设置为 YES,并在更改文本后设置为 NO.

We just set YES the setScrollEnabled in UITextView before we change the text in UITextView and set NO after we change the text.

这里是示例代码

[yourTextView setScrollEnabled:YES];
yourTextView.text = [someString copy];
[yourTextView setScrollEnabled:NO];

:)