我的应用程序中有自动滚动功能。当它被激活时,我的代码禁用 textView 滚动并使用 CADisplayLink
更改 contentOffset。
在早期版本的 iOS 中工作正常,但在 7th 中文本出现裁剪。
虽然进一步发现,但我发现 contentSize
在我禁用 textView 滚动后的一段时间内发生了变化。看起来像是某种优化。但它不考虑 contentOffset
。
要重现此错误:
- 确保 textView 中的文本足够大,至少两页大小。
- 在 ViewController 中将
_textView.scrollEnabled = NO;
放入-viewDidLoad
在 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/