NScrollView不适用于打开的图像

时间:2013-07-09 07:38:29

标签: objective-c xcode macos nsscrollview

我在NSWindow视图中添加了界面构建器的scrollview,并在NSScrollview中添加了CustomView我在我的

中使用了此代码行

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属性NSScrollViewNSScrollViewNSView与CustomView,CustomView与CustomView相关联。 调用-awakeFromNib 问题是因为NSScrollView当我打开图像时,我得到空白窗口而不是打开图像,滚动没有NSScrollView图像打开正确的任何想法如何解决它?

1 个答案:

答案 0 :(得分: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) ];
}