【问题标题】:Making Spotlight Search Bar like view in Objc/Swift在 Objc/Swift 中制作像视图一样的 Spotlight 搜索栏
【发布时间】:2020-05-07 08:28:52
【问题描述】:

我正在尝试复制 Spotlight 的视图行为。已使用以下方法向 NSWindow 添加了模糊的自适应背景:

NSVisualEffectView *visualEffectView =  [[NSVisualEffectView alloc] initWithFrame:[self bounds]];
[visualEffectView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
visualEffectView.material = NSVisualEffectMaterialMediumLight;
visualEffectView.blendingMode = NSVisualEffectBlendingModeBehindWindow;
visualEffectView.wantsLayer = true;
visualEffectView.state = NSVisualEffectStateActive;
visualEffectView.layer.cornerRadius = 7.5;
[self addSubview:visualEffectView];

问题是背景确实有效,但窗口内的文本和其他元素不能正确适应窗口下方的背景。

这是图片。

.

【问题讨论】:

    标签: objective-c swift xcode macos


    【解决方案1】:

    解决了。通过将子视图添加到 visualEffectView 而不是 self。

    【讨论】:

      猜你喜欢
      • 2011-03-10
      • 1970-01-01
      • 1970-01-01
      • 2016-07-27
      • 2021-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多