[yourTextView scrollRectToVisible:CGRectMake(0,0,1,1) animated:YES];
或者
在viewDidLayoutSubviews
中设置内容偏移量,以使其生效。
- (void)viewDidLayoutSubviews {
[yourTextView setContentOffset:CGPointZero animated:NO];
}
在viewDidLoad
方法中
[yourTextView scrollRangeToVisible:NSMakeRange(0, 1)];
contentTextView.scrollRangeToVisible(NSRange(location: 0, length: 0))
self.textView.scrollRectToVisible(CGRect.init(x: 0, y: 0, width: 1, height: 1), animated: false)
- Rory PriorscrollRangeToVisible
。我的文本视图是不可编辑的,我测试了可选择和不可选择两种情况(两种情况都没有影响结果)。[textview scrollRectToVisible:NSRange(0, 0) animated:YES];