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

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

问题描述

我为我的应用程式使用 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天全站免登陆