2
メインウィンドウにNSDrawerがあるアプリケーションで作業しています。引き出しが常に右端に開かれることが重要です。それは、それがどのように動作するようにコード化したかです。私が知りたいのは、引き出しが「画面外」で開くかどうかを検出する方法があるかどうかです...これを検出できる方法はありますか?もしそうなら、どうですか?さらに、メインウィンドウをどのように動かすことで、開くことができる引き出しの幅に合わせることができますか?NSDrawerが画面から開くかどうかを検出する方法
ありがとうございます。
ニック
EDIT:
ここでは、ソリューションは、ロブの提案のおかげです。
-(IBAction)toggleDrawer:(id)sender
{
NSRect screenFrame = [[[NSScreen screens] objectAtIndex:0] visibleFrame];
NSRect windowFrame = [window frame];
NSRect drawerFrame = [[[drawer contentView] window] frame];
if ([drawer state] == NSDrawerOpenState)
{
[drawer close];
}
else
{
if (windowFrame.size.width +
windowFrame.origin.x +
drawerFrame.size.width > screenFrame.size.width)
{
NSLog(@"Will Open Off Screen");
float offset = (windowFrame.size.width +
windowFrame.origin.x +
drawerFrame.size.width) - screenFrame.size.width;
NSRect newRect = NSMakeRect(windowFrame.origin.x - offset,
windowFrame.origin.y,
windowFrame.size.width,
windowFrame.size.height);
[window setFrame:newRect display:YES animate:YES];
}
[drawer openOnEdge:NSMaxXEdge];
}
}
パーフェクト。ありがとうございました。私が質問に使用したコードを追加しました。 – nrj
すてきな解決策、皆さん! 'newRect'の' offset'を原点ではなく幅から減算することもできます。 –