[英]NSTextView always scrolls to bottom. How do I force it to display at the top?
I have an NSTextView in my XIB UI. 我的XIB UI中有一个NSTextView。 In my code, I do
用我的代码
[textview insertText:@"text i put here"];
many times, and then finally 很多次,最后
[textview setEditable:NO];
BTW, this is to create an information panel for my app. 顺便说一句,这是为我的应用程序创建一个信息面板。
When I run my app though, the text view always scrolls to the bottom. 但是,当我运行我的应用程序时,文本视图始终滚动到底部。 Is there any way to make it start at the top?
有什么办法让它从顶部开始?
Try with this method 尝试这种方法
[textview scrollToBeginningOfDocument:self];
or 要么
//NSTextView inside an NSScrollView you can create object for that scrollview //在NSScrollView内的NSTextView可以为该scrollview创建对象
[scrollView.contentView scrollToPoint:NSMakePoint(0, scrollView.documentView.frame.size.height-scrollView.contentSize.height)];
If you insert a NSTextView with Interface Builder, it will actually reside inside of NSScrollView. 如果使用Interface Builder插入NSTextView,它实际上将驻留在NSScrollView内部。 Interface Builder automatically do this.
Interface Builder会自动执行此操作。
I mean, this is normal scroll view behavior and you can do 'scroll to top' as usually. 我的意思是,这是正常的滚动视图行为,您可以像往常一样“滚动到顶部”。
In Swift one can do 在Swift中可以做到
textView.scroll(NSPoint.zero)
where one loads content 一个加载内容的地方
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.