gpt4 book ai didi

macos - NSShadow 绘图错误

转载 作者:行者123 更新时间:2023-12-03 17:14:13 29 4
gpt4 key购买 nike

您好,在我的应用程序中,我有一个带有 CALayer 的自定义 View (我将其用于过渡动画),在该 View 中我添加了一些 subview ,其中之一是带有 NSTableView 的 View 。 NSTableView 的每个单元格都用阴影绘制其内容。代码如下:

NSShadow* shadow = [[NSShadow alloc] init];
[shadow setShadowOffset:NSMakeSize(2.0, -2.0)];
[shadow setShadowBlurRadius:2.0];
[shadow setShadowColor:[[NSColor blackColor] colorWithAlphaComponent:0.3]];
[shadow set];

[self.stringValue drawInRect:NSMakeRect(x, y, w - 60, h) withAttributes:attributes];

当我的 NSTableView 的 CALayer 打开时少于约 50 行时,或者当我在 IB 中关闭 CALayer 时,我会像这样绘制单元格:/image/zMxmK.png

但是当我的 NSTableView 有超过 50 行并且我在 IB 中打开 CALayer 时,我会像这样绘制单元格:/image/IMyIP.png

怎么可能呢?我打破了我的:(

最佳答案

  • 尝试根据 [[NSGraphicsContext currentContext] isFlipped] 属性将 -2.0 更改为 +2.0
  • 尝试根据 View 是否分层以及 CALayer 是否启用了 isGeometryFlipped 来更改它。
  • 如果您应用了翻转变换,请注意它们不会影响 NSShadow:

    Shadows are always drawn in the default user coordinate space, regardless of any transformations applied to that space. This means that rotations, translations and other transformations of the current transformation matrix (the CTM) do not affect the resulting shadow. Another way to think about this is that changes to the CTM do not move or change the apparent position of the shadow’s light source.

关于macos - NSShadow 绘图错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11581045/

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