使用 CGDisplay 显示窗口时,文本字段显示为不可编辑

发布于 2024-11-14 09:11:32 字数 1345 浏览 2 评论 0原文

我正在制作一个应用程序,其中:

  1. 当用户选择显示菜单选项时 ->该窗口显示在整个屏幕上,
  2. 当用户选择隐藏菜单选项时 - >整个屏幕上可见的窗口将被隐藏。

问题是——

当我执行步骤 1 然后执行步骤时 第2步然后第1步,窗口没有 与第一次出现时一样 时间。

谁能建议我,我该如何解决?

以下是代码部分:

- (IBAction)hideMenuAction:(id)sender
{   
    [window orderOut:nil];
    if (CGDisplayRelease( kCGDirectMainDisplay ) != kCGErrorSuccess) {
           NSLog( @"Couldn't release the main display!" );
        }
}

- (IBAction)displayMenuAction:(id)sender
{
    [window makeKeyAndOrderFront:nil];
        if (CGDisplayCapture( kCGDirectMainDisplay ) != kCGErrorSuccess) {
           NSLog( @"Couldn't capture the main display!" );
        }
    [window setLevel:CGShieldingWindowLevel()];
}

编辑:

当我放置代码行时,问题得到解决: [window makeKeyAndOrderFront:nil];在 displayMenuAction 中的 if 块下方。使用的代码是-

- (IBAction)displayMenuAction:(id)sender
{
     if (CGDisplayCapture( kCGDirectMainDisplay ) != kCGErrorSuccess) {
           NSLog( @"Couldn't capture the main display!" );
        }
    [window makeKeyAndOrderFront:nil];
    [window setLevel:CGShieldingWindowLevel()];
}

但我开始面临一个新问题:

当我执行步骤 1 然后执行步骤时 第 2 步然后第 1 步,窗口上的文本字段是 显示为不可编辑。我尝试设置 它们在代码中是可编辑的,但事实并非如此 工作。

请建议。

I am making an application in which:

  1. when user selects display menu option -> the window is displayed over whole screen and
  2. when user selects hide menu option - >the window which was visible over whole screen gets hidden.

Problem is -

When I am performing step 1 then step
2nd then step 1, the window does not
appear as it appeared for the first
time.

Can anyone suggest me, how can I resolve it?

Below is the part of code:

- (IBAction)hideMenuAction:(id)sender
{   
    [window orderOut:nil];
    if (CGDisplayRelease( kCGDirectMainDisplay ) != kCGErrorSuccess) {
           NSLog( @"Couldn't release the main display!" );
        }
}

- (IBAction)displayMenuAction:(id)sender
{
    [window makeKeyAndOrderFront:nil];
        if (CGDisplayCapture( kCGDirectMainDisplay ) != kCGErrorSuccess) {
           NSLog( @"Couldn't capture the main display!" );
        }
    [window setLevel:CGShieldingWindowLevel()];
}

Edit:

The problem is resolved when I placed the code line: [window makeKeyAndOrderFront:nil]; below the if block in displayMenuAction. The code used is-

- (IBAction)displayMenuAction:(id)sender
{
     if (CGDisplayCapture( kCGDirectMainDisplay ) != kCGErrorSuccess) {
           NSLog( @"Couldn't capture the main display!" );
        }
    [window makeKeyAndOrderFront:nil];
    [window setLevel:CGShieldingWindowLevel()];
}

But I have started facing a new problem:

When I am performing step 1 then step
2nd then step 1, the text fields on window are
appearing un-editable. I tried to set
them as editable in code but it didn't
work.

Please suggest.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩心不撩汉 2024-11-21 09:11:32

窗口是在笔尖中定义的吗?如果是这样,“关闭时释放”复选框是否处于活动状态?如果是,当窗口关闭时,它将被释放。

Is the window defined in a nib? If so, is the "Release when closed" checkbox active? If it is, when the window is closed it will be deallocated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文