将搜索框放在标题栏的左侧 [英] Position the search box at the left of the title bar

查看:22
本文介绍了将搜索框放在标题栏的左侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的应用程序使用 INAppStoreWindow.我在应用程序的标题栏中放置了一个 NSSearchButton.

I'm using INAppStoreWindow for my application. I put an NSSearchButton in the title bar of the application.

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);

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

The previous code positioned the search box at the center of the title bar. What I want to do is position the search box at the left side of the title bar and if "Maximize" button of the application is clicked, I want the search box to remain at left. (not exact left. I want the left where there is a space between the search box and the left edge of the title bar).

当然,我想为全屏"箭头留出空间.

Of course, I want to leave a space for the "full screen" arrows.

我对 Cocoa 开发还不是很熟悉.
如何根据需要定位我的搜索框?

I'm not really familiar with Cocoa development (yet).
How to position my search box as I want?

推荐答案

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

You will have to register to the notifications (NSWindowWillExitFullScreenNotification, NSWindowWillEnterFullScreenNotification) and adjust the frame of the button accordingly.

例如

    [[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
}

希望能帮到你

这篇关于将搜索框放在标题栏的左侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆