0

我添加了带有界面构建器的滚动视图,它在NSWindow视图中实现,并且在NSScrollview我添加了自定义视图中,我在我的

AppDelegate.m

- (void)awakeFromNib

id docView = paintingfield;
id viewas = [[NSScrollView alloc] initWithFrame:
                            [[scrollview contentView] frame]];
[scrollview setHasVerticalScroller:YES];
[scrollview setHasHorizontalScroller:YES];
[scrollview setBorderType:NSNoBorder];
[scrollview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[scrollview setDocumentView:docView];
[scrollview setContentView:viewas];

在我的 AppDelegate.h

IBOutlet NSScrollView * scrollview;
IBOutlet NSView * view;
IBOutlet CustomView *paintingfield;

IBOutlets正确链接NSScrollView到CustomView NSScrollViewNSViewCustomView 到 CustomView。 -awakeFromNib被称为问题是因为NSScrollView当我打开图像时,我得到空白窗口,而不是打开的图像,没有NSScrollView图像的滚动也可以正常打开任何想法我该如何解决?

4

1 回答 1

0

尝试像这样更改您的代码:

- (void)awakeFromNib
{
    [scrollview setHasVerticalScroller:YES];
    [scrollview setHasHorizontalScroller:YES];
    [scrollview setBorderType:NSNoBorder];
    [scrollview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
    [scrollview setDocumentView:paintingfield];
    [scrollView.documentView setFrame: CGRectMake(0, 0, paintingfield.frame.size.width,paintingfield.frame.size.height) ];
}
于 2013-07-09T08:22:08.383 回答