NSScrollView 内的 NSTextView 不滚动:(
我在独立的 Cocoa 测试应用程序中有以下代码:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSView *contentView = [window contentView];
NSTextStorage *textStorage = [NSTextStorage new];
NSLayoutManager *layoutManager = [NSLayoutManager new];
NSTextContainer *textContainer = [NSTextContainer new];
[textContainer setHeightTracksTextView:YES];
[textContainer setWidthTracksTextView:YES];
[textStorage addLayoutManager:layoutManager];
[layoutManager addTextContainer:textContainer];
NSScrollView *scrollView = [[NSScrollView alloc] initWithFrame:[contentView bounds]];
[scrollView setHasVerticalScroller:YES];
[scrollView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[scrollView setBorderType:NSNoBorder];
NSRect textFrame;
textFrame.origin = NSZeroPoint;
textFrame.size = [NSScrollView contentSizeForFrameSize:[scrollView frame].size hasHorizontalScroller:NO hasVerticalScroller:YES borderType:NSNoBorder];
NSTextView *textView = [[[NSTextView alloc] initWithFrame:textFrame textContainer:textContainer] autorelease];
[textView setAutoresizingMask:NSViewWidthSizable];
[scrollView setDocumentView:textView];
[contentView addSubview:scrollView];
}
我试图在 NSTextView+NSScrollView 组合中设置所涉及的对象的整个层次结构(包括文本系统对象),只是为了看看它们是如何协同工作的。但是,当我运行此命令并开始向文本视图添加一堆行时,当文本长度超过视图高度时,它不会滚动。就好像 NSScrollView 和 NSTextView 不知道彼此。为了使这里的所有内容都能正确通信,我缺少哪些连接?
编辑:是的,这是泄漏且丑陋的。 :) 编写本文只是为了尝试确定这里发生的情况,而不是生产代码或我将再次直接使用的任何内容。承诺。
I have the following code in a stand-alone Cocoa test app:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSView *contentView = [window contentView];
NSTextStorage *textStorage = [NSTextStorage new];
NSLayoutManager *layoutManager = [NSLayoutManager new];
NSTextContainer *textContainer = [NSTextContainer new];
[textContainer setHeightTracksTextView:YES];
[textContainer setWidthTracksTextView:YES];
[textStorage addLayoutManager:layoutManager];
[layoutManager addTextContainer:textContainer];
NSScrollView *scrollView = [[NSScrollView alloc] initWithFrame:[contentView bounds]];
[scrollView setHasVerticalScroller:YES];
[scrollView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[scrollView setBorderType:NSNoBorder];
NSRect textFrame;
textFrame.origin = NSZeroPoint;
textFrame.size = [NSScrollView contentSizeForFrameSize:[scrollView frame].size hasHorizontalScroller:NO hasVerticalScroller:YES borderType:NSNoBorder];
NSTextView *textView = [[[NSTextView alloc] initWithFrame:textFrame textContainer:textContainer] autorelease];
[textView setAutoresizingMask:NSViewWidthSizable];
[scrollView setDocumentView:textView];
[contentView addSubview:scrollView];
}
I'm trying to set up the whole hierarchy of objects involved (including the text system objects) in a NSTextView+NSScrollView combination just to see how it all works together. However when I run this and start adding a bunch of lines to the text view, it doesn't scroll when the text gets longer than the view is tall. It's as if the NSScrollView and the NSTextView aren't aware of each other. What connections am I missing to get everything here to communicate correctly?
EDIT: Yes, this is leaky and ugly. :) This was written just to try to determine what's going on here, not production code or anything I'll be using directly ever again. Promise.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用 -setHorizontallyResizable: 和 -setVerticallyResizing:?
Have you tried playing with -setHorizontallyResizable: and -setVerticallyResizable:?