0

我正在使用此代码显示面板:

- (void)displayPanelWithView:(NSView *)view andTitle:(NSString *)title {
    [panel setTitle:title];    
    if ([windows count] < 1) {
        [panel setContentSize:[view frame].size];
        [panel setContentView:view];
        [panel center];
        [panel makeKeyAndOrderFront:nil];
    }
    else {
        [panel setContentSize:[view frame].size];
        [panel setContentView:view];
        [NSApp beginSheet:panel modalForWindow:[windows objectAtIndex:0] modalDelegate:self     didEndSelector:nil contextInfo:NULL];
    }
}

panel是一个 IBOutlet(它在 IB 中实例化)。它是 NSPanel 的子类。

windows是一个窗口数组。如果没有窗口,则面板显示为新窗口。

问题

当我显示具有特定视图且不windows为空的面板时,该面板显示为工作表。第一次发生这种情况时,总会有一个偏移量。以下是该方法第一次调用和第二次调用的截图(均为非空):windows

第一次

第二次

如果我使用这个,这个错误会消失:

[panel setStyleMask:NSBorderlessWindowMask];

在这种情况下,尺寸是正确的,但是工作表不再聚焦并且保持不聚焦(因此上述屏幕截图中的蓝色按钮一直是白色的)。我该怎么做才能让工作表每次都能正确显示?第一次会发生什么下次不会发生?

4

1 回答 1

0

I've managed to solve the issue by using this code instead :

- (void)displayPanelWithView:(NSView *)view andTitle:(NSString *)title {
    [panel setTitle:title];    
    if (![defaults floatForKey:@"SS_Interface_Mode"] == 0 || [windows count] < 1) {
        [panel setContentSize:[view frame].size];
        [[panel contentView] addSubview:view];
        [panel center];
        [panel makeKeyAndOrderFront:nil];
    }
    else {
        [panel setContentSize:[view frame].size];
        [[panel contentView] addSubview:view];
        [NSApp beginSheet:panel modalForWindow:[windows objectAtIndex:0] modalDelegate:self didEndSelector:nil contextInfo:NULL];
    }
}
- (IBAction)endSheet:(id)sender {
    [NSApp endSheet:panel];
    [panel orderOut:nil];
    for (NSView *view in [[panel contentView] subviews])
        [view removeFromSuperview];
}

As you can see, I add the view to the current content view of the panel instead of assigning it as the new content view of the panel.

于 2013-08-13T19:04:50.033 回答