2013-07-09 41 views
0

工作,我有添加滾動視圖與界面構建及其在NSWindow鑑於實施和NSScrollview我加入CustomView我使用這行代碼在我NScrollView不打開的圖像

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被propertly鏈接NSScrollViewNSScrollViewNSView到CustomView,CustomView到CustomView。 -awakeFromNib被稱爲 問題是因爲NSScrollView當我打開圖像我得到空白窗口,而不是打開圖像滾動沒有NSScrollView圖像打開適當太任何想法我怎麼能修復它?

+0

嘗試刪除行[滾動視圖的setContentView:viewas]。 – stosha

+0

如果我刪除這一行我得到空的窗口沒有任何查看或打開圖像 – kosas

+0

hmm但我刪除此行和自定義視圖從NSScrollView在界面我得到一個打開的圖像與某種滾動視圖我會嘗試與現在的工作 – kosas

回答

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) ]; 
} 
+0

它的工作原理,但只有當我把這條線在開放圖像方法感謝​​幫助! – kosas