ios - UITextView setContentOffset with scrollEnabled=NO in iOS7

标签 ios uikit uitextview ios7

我的应用程序中有自动滚动功能。当它被激活时,我的代码禁用 textView 滚动并使用 CADisplayLink 更改 contentOffset。

在早期版本的 iOS 中工作正常,但在 7th 中文本出现裁剪。

虽然进一步发现,但我发现 contentSize 在我禁用 textView 滚动后的一段时间内发生了变化。看起来像是某种优化。但它不考虑 contentOffset

要重现此错误:

  1. 确保 textView 中的文本足够大,至少两页大小。
  2. 在 ViewController 中将 _textView.scrollEnabled = NO; 放入 -viewDidLoad
  3. 在 ViewController 中添加:

    - (void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
        [_textView setContentOffset:CGPointMake(0, 400) animated:YES];
    }
    

问题是:当 scrollEnabled 设置为 NO 时,如何在 iOS7 中自动滚动 UITextView

禁用滚动以停止可能的 UITextView 插入符号位置更改时的内置自动滚动,并禁止用户与控件交互。

最佳答案

如果您的文本在底部被裁剪,而 scrollEnabled 为 NO:

self.textContainerInset = UIEdgeInsetsMake(0.0f, 0.0f, -20.0f, 0.0f);

关于ios - UITextView setContentOffset with scrollEnabled=NO in iOS7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18825529/

相关文章:

ios - 当在 UISearchBar 中粘贴搜索字段时,searchBar textDidChange 被调用两次

multithreading - iOS 推送通知 - 应用程序 :didRegisterForRemoteNotificationsWithDeviceToken: execute in main thread?

ios - 如何设置 "if there is text in text view"

ios - UIButton 的两种方法?

ios - UIPageControl 不适用于 voiceOver

ios - 更改AppID之后是否需要编辑配置

objective-c - iOS自定义状态栏仅替换运营商图标

ios - 如何在swift中制作系统字体 "Black Italic"?

uitextview - Xcode 9 UITextView链接不再可单击

swift - 基于 Swift 内容的动态 UITextView 大小