親ウィンドウのサイズを変更すると、NSView の内容が比例して拡大縮小されるようにするために行ったことは次のとおりです。まず、インターフェイス ビルダーで NSView をウィンドウに追加し、それへの参照を AppDelegate に追加しました。私のはたまたま呼ばれていscrollView
ます。からすべての自動サイズ変更動作を削除しましたscrollView
。
次に、AppDelegate にこれを追加しました。
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// keep the aspect ratio constant so that the content looks good
[window setContentAspectRatio:NSMakeSize(2, 1)];
window.delegate = self;
}
- (void)windowDidResize:(NSNotification *)notification {
// size the scrollView to fill the window, but keep its bounds constant
NSRect rect = [[window contentView] frame];
NSRect oldBounds = [scrollView bounds];
[scrollView setFrame:rect];
[scrollView setBounds:oldBounds];
}
これにより、AppDelegate もウィンドウ デリゲートに変わります。私はそれに多くのロジックを持っていないので、結構です。フレームを変更しながら境界を一定に保つことで、 のコンテンツはscrollView
スムーズに縮小されます。