我有一个 NSWindow,我以模态方式显示在其他窗口上以显示警报。代码是:
// This code is in MyAlert .m file. MyAlert inherits from NSWindow
- (void)showInWindow:(NSWindow *) {
[window beginSheet:self completionHandler:NULL];
}
问题是,当在运行 Mojave 的 Mac 中使用 Xcode 10.1 编译时,我看到警报后面有一个灰色的“模糊”视图,这是我不希望出现的:我希望显示它的背景窗口可见。
使用 Xcode 9.4.1 编译的相同代码不会显示此模糊视图。
此外,我调试了 UI,确实在 Xcode 10.1 编译版本中插入了一个 NSVisualEffectView,在 9.4.1 上编译时不存在,但我似乎找不到摆脱它的方法。下面是两个版本中调试的 UI 截图。
有人面对并解决了这个问题吗?
更新(插入 nsvisualeffectview 的最小项目重现问题):http ://s000.tinyupload.com/?file_id=43114618701497778758
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
__weak typeof(self)weakSelf = self;
NSView *contentView = self.window.contentView;
contentView.wantsLayer = YES;
[self.window setOpaque:NO];
[self.window setHasShadow:NO];
contentView.layer.backgroundColor = [NSColor redColor].CGColor;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf showAlert];
});
}
- (void)showAlert {
DummyAlertWindowController *alertController = [[DummyAlertWindowController alloc] initWithWindowNibName:@"DummyAlertWindowController"];
[self.window beginSheet:alertController.window completionHandler:^(NSModalResponse returnCode) {
;
}];
}
@implementation DummyAlertWindowController
- (void)windowDidLoad {
[super windowDidLoad];
self.properContentView.wantsLayer = YES;
self.properContentView.layer.backgroundColor = [NSColor blueColor].CGColor;
[self.window setOpaque:NO];
[self.window setHasShadow:NO];
self.window.contentView.wantsLayer = YES;
self.window.contentView.layer.backgroundColor = [NSColor clearColor].CGColor;
}
@end