添加文本时,如何使带有 UITextView 子视图的 UIScrollView 不滚动? [英] How to make a UIScrollView with a UITextView sub view not scroll when adding text?

查看:52
本文介绍了添加文本时,如何使带有 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];

:)

这篇关于添加文本时,如何使带有 UITextView 子视图的 UIScrollView 不滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆