gpt4 book ai didi

macos - 将搜索框置于标题栏左侧

转载 作者:行者123 更新时间:2023-12-03 17:11:42 31 4
gpt4 key购买 nike

我正在使用INAppStoreWindow对于我的申请。我在应用程序的标题栏中放置了一个 NSSearchButton

INAppStoreWindow *aWindow = (INAppStoreWindow*)self.window;
aWindow.titleBarHeight = 60.0;
aWindow.showsTitle = YES;

NSView *titleBarView = aWindow.titleBarView;
NSSize buttonSize = NSMakeSize(200.f, 100.f);
NSRect buttonFrame =
NSMakeRect(NSMidX(titleBarView.bounds) - (buttonSize.width / 2.f),
NSMidY(titleBarView.bounds) - (buttonSize.height / 2.f),
buttonSize.width,
buttonSize.height);

前面的代码将搜索框定位在标题栏的中心。我想要做的是将搜索框放置在标题栏的左侧,如果单击应用程序的“最大化”按钮,我希望搜索框保持在左侧。 (不是精确的左侧。我想要搜索框和标题栏左边缘之间有空格的左侧)。

当然,我想为“全屏”箭头留出空间。

我还不太熟悉 Cocoa 开发。
如何根据需要定位搜索框?

最佳答案

您必须注册通知(NSWindowWillExitFullScreenNotification、NSWindowWillEnterFullScreenNotification)并相应地调整按钮的框架。

例如

    [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(windowWillEnterFullScreen:)
name:NSWindowWillEnterFullScreenNotification
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(windowWillExitFullScreen:)
name:NSWindowWillExitFullScreenNotification
object:nil];

然后

- (void)windowWillEnterFullScreen:(NSNotification *)notification
{
// set your button frame to the left
}


- (void)windowWillExitFullScreen:(NSNotification *)notification
{
// set your button frame back to the centre
}

希望这有帮助

关于macos - 将搜索框置于标题栏左侧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22822458/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com