2011-12-21 2 views
2

私をご紹介させてください。私はc、C++、Javaの経験を持ち、Mac OS X上のObjective-CとCocoaで始まる熱心なプログラマー(専門家ではない)です。Cocoaで第2の垂直分割ビューを表示/非表示にする方法は?

私の最初のプログラムでは、ボタンを押すごとに表示/非表示になるように、左側に1つ(メイン)が常時オン、右側に1つの垂直分割ビューを作成したいと思います(その出力はデバッグ出力用です) 。

Xcode 4.2では、ナビゲータ/デバッグ/ユーティリティを表示/非表示にすることができます。私は "ユーティリティ"の行動を探しています、それはまさに私が望むものです。その垂直ビューの使い方は私のプログラムから "デバッグ"テキストを出力することです。NSScrollViewでNSTextViewを使って "Console"をシミュレートすることを考えています。私はXcodeのTerminalまたはDebugビューを使うことができることを知っています。これが現在動作しています。どのようにそれをやって、私のプログラムを改善するかを学ぶために必要です。

私はグーグルをよく似たリクエストを読んでいますが、これを行う方法を正確に見つけることができませんでした。

ご協力いただきありがとうございます。

ルイス

答えて

0

非常に大まかな考えです。 ofDividerAtIndex:setPositionとビューの幅を変更 setPosition(CGFloat)位置ofDividerAtIndex:(NSInteger)は

CGFloatを宣言splitterlengthをdividerIndex。

これをapplicationDidFinishLaunchingに入れます。

splitterlength = splitView.bounds.size.width; 
[splitView setPosition:splitterlength ofDividerAtIndex:0]; 

次にあなたが欲しい、これまでどのような長さ

 - (IBAction)moveSplitter:(id)sender { 

    NSArray *splitterViews =splitView.subviews; 
    CGFloat splitterCheckLength =[[splitterViews objectAtIndex:0]bounds].size.width; 
    CGFloat openSplitter=splitterlength/2; 

    if (splitterCheckLength ==openSplitter) { 
     [splitView setPosition:splitterlength ofDividerAtIndex:0]; 
    }else { 
     [splitView setPosition:openSplitter ofDividerAtIndex:0]; 
    } 




} 

使用このアクションを使用します。

これを言うと、私は通常のcustomViewsを使用し、それらを調整します。そうすることで、ユーザーがスプリッタをドラッグすることについて心配する必要はありません。

+0

ありがとうございます。@markhunte。私はそれをテストし、それは非常にうまく動作します。また、これに対処する方法の全体的なアイデアを私に与えました。ここで別の興味深いトピックを見つけた[リンク](http://stackoverflow.com/questions/925020/how-to-expand-and-collapse-parts-of-nssplitview-programatically/1103242#1103242)。私はこれについてもっと学び、終わったら私の最終的なコードを掲示します。再度、感謝します。ルイス –

1

私が最終的に私の問題を解決するために約束したとおりです。

  • 目的:
    • ボタン右のビューとウィンドウがそれに応じてサイズを変更表示/非表示にする:私は2つの垂直分割さビューを望みます。
    • 常にオンオンでNONサイズ変更可能(高さでサイズ変更可能)
    • 右/表示/非表示、幅/高さのサイズ変更が可能で、常に最小幅でなければなりません。
    • 右が隠されている場合は、メインウィンドウの最小幅/高さが

左ビューに等しい私は2カスタムビューの十分な自動サイズ制限のあるInterface Builderで(「スプリング」でNSSplitView(垂直)を作成/ 'ストラット')。

Controller.h 
: 
@interface Controller : NSWindowController <NSSplitViewDelegate, NSWindowDelegate> { 
: 


Controller.m 
: 
// To control the Splitter (next 3 methods) 
// ======================================= 
// The splitter cannot be moved. I always return "widthViewLeft" which is "fixed static sized to the left view width" 
// I return NO to resize the left panel and YES to the right panel. 

-(CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)dividerIndex { 
    return (widthViewLeft);  
} 
-(CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)dividerIndex { 
    return (widthViewLeft); 
} 
-(BOOL)splitView:(NSSplitView *)splitView shouldAdjustSizeOfSubview:(NSView *)subview { 
    return subview != splitViewLeft; 
} 

// To control the Main Window resize 
// ======================================= 
// I allow to resize if the Right panel is open. 
// I restrict to a fixed size if the Right panel is closed(hidden), so I don't allow to resize. 

- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize 
{ 
    if ([[leftViewController view] isHidden ]) { 
     proposedFrameSize.width = widthViewLeft + 2; 
     proposedFrameSize.height = heightViewLeft + titleBarHeight + 2; 
    }  
    return proposedFrameSize; 
} 


// To HIDE the right panel 
// ======================================= 
// 
-(void)handleNotificationHideConsola:(NSNotification *)pNotification 
{ 
    NSRect newFrame; 
    NSSize newMinSize; 
    NSSize newMaxSize; 

    // Hide the right panel 
    [[rightViewController view] setHidden:TRUE]; 

    // Values that do not change 
    newMinSize.height = [theWindow minSize].height;  
    newMaxSize.height = [theWindow maxSize].height;  
    newFrame.origin.x = [theWindow frame].origin.x; 
    //newFrame.origin.y = [theWindow frame].origin.y; 

    // Values that change 
    newMinSize.width = widthViewLeft; 
    newMaxSize.width = widthViewLeft; 
    newFrame.size.width = widthViewLeft + 2; 
    newFrame.size.height = heightViewLeft + titleBarHeight + 2; 
    newFrame.origin.y = [theWindow frame].origin.y + ([theWindow frame].size.height - newFrame.size.height) ; 

    // Perform the change 
    [theWindow setMinSize:newMinSize]; 
    [theWindow setFrame:newFrame display:YES animate:YES]; 

} 

// To SHOW the right panel 
// ======================================= 
// 
-(void)handleNotificationShowConsola:(NSNotification *)pNotification 
{ 
    if ([[rightViewController view] isHidden]) { 
     NSRect newFrame; 
     NSSize newMinSize; 

     // Show the right panel 
     [[rightViewController view] setHidden:FALSE]; 

    // Values that do not change 
     newMinSize.height = [theWindow minSize].height;  
     newFrame.origin.x = [theWindow frame].origin.x; 
     newFrame.origin.y = [theWindow frame].origin.y ; 

     // Values that change 
     newMinSize.width = widthViewLeft + widthViewRigth;    
     newFrame.size.width = widthViewLeft + widthViewRigth;   
     newFrame.size.height = newMinSize.height + titleBarHeight; 
     newFrame.origin.y = [theWindow frame].origin.y - (newFrame.size.height - [theWindow frame].size.height); 

     // Perform the change 
     [theWindow setMinSize:newMinSize]; 
     [theWindow setFrame:newFrame display:YES animate:YES]; 
    } 
} 

はアイデアのため@markhunteありがとうございましたし、上記のサンプルは、他の誰かの役に立てば幸い:それから私は次のようでした。

ルイス

関連する問題