gpt4 book ai didi

macos - 阴影效果不适用于可调整大小的 NSView

转载 作者:行者123 更新时间:2023-12-03 17:01:43 25 4
gpt4 key购买 nike

我为我的 NSView 编写了以下阴影效果代码。

    [_nsview setWantsLayer:YES];
_nsview.layer.masksToBounds = NO;
_nsview.layer.cornerRadius = 5;
_nsview.layer.shadowOffset = CGSizeMake(.3f, -.3f);
_nsview.layer.shadowRadius = 10;
_nsview.layer.shadowOpacity = 0.20;
_nsview.layer.shadowColor = [NSColor blackColor].CGColor;

_nsview 是该 NSView 的导出。上面的代码工作完美并给出了阴影效果...但问题是在调整 _nsview 大小后阴影会隐藏。

This is after running my sample app, shadow effect working perfectly

This is after resizing main window of sample app(_nsview has auto layout constraints, due to that it will also resize with main window)

最佳答案

使用 NSShadow 代替:

    [_childView setWantsLayer:YES];
_childView.layer.backgroundColor = [NSColor whiteColor].CGColor;
_childView.layer.cornerRadius = 5;

NSShadow *dropShadow = [[NSShadow alloc] init];
[dropShadow setShadowColor:[NSColor colorWithWhite:0.1 alpha:0.6]];
[dropShadow setShadowOffset:NSMakeSize(0, -5)];
[dropShadow setShadowBlurRadius:5];
_childView.shadow = dropShadow;

关于macos - 阴影效果不适用于可调整大小的 NSView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38911009/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com