本文介绍了如何使NSWindow看起来禁用,不响应用户输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定有一些系统级的功能。无论如何,有没有办法使NSWindow看起来禁用,并且不回应用户输入?

I'm not sure that there's some system-level feature like that. Anyway, is there a way to make NSWindow looks disabled and does not respond to user input?

推荐答案

我不认为mdominick的答案是正确的。因为我只是想禁用NSTextFields和NSButtons,我想出了:

I don't think mdominick's answer is correct. Since I only wanted to disable the NSTextFields and NSButtons, I came up with this:

for (NSView *item in [self.window.contentView subviews])
{
    if ([item isKindOfClass:[NSTextField class]] || [item isKindOfClass:[NSButton class]])
    {
        [(id)item setEnabled:NO];
    }
}

EDIT

在处理新应用程序时,在NSWindow的子类中此方法非常方便

Whilst working on a new app, this method in a subclass of NSWindow was really convenient

- (void)setEnabled:(BOOL)enabled
{
    [self setEnabled:enabled view:self.window.contentView];
}

- (void)setEnabled:(BOOL)enabled view:(id)view
{
    if ([view isHidden]) return;

    for (NSView *item in [view subviews])
    {
        if ([item isKindOfClass:[NSProgressIndicator class]])
        {
            NSProgressIndicator *pI = (NSProgressIndicator *)item;
            [pI setHidden:enabled];
            if (!enabled) [pI startAnimation:nil];
            if (enabled) [pI stopAnimation:nil];
        }
        if ([item isKindOfClass:[NSTextField class]] || [item isKindOfClass:[NSButton class]] || [item isKindOfClass:[NSTextView class]])
        {
            [(id)item setEnabled:enabled];
            continue;
        }
        if (item.subviews.count)
        {
            [self setEnabled:enabled view:item];
        }
    }
}

这篇关于如何使NSWindow看起来禁用,不响应用户输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 03:31