【问题标题】:Can't round corners and have background colour on ASDisplayNode不能圆角并在 ASDisplayNode 上具有背景颜色
【发布时间】:2020-11-30 09:08:30
【问题描述】:

我正在尝试创建一个带有圆角的 ASDisplayNode,同时设置其背景颜色。然而,角落从不显得圆润。为什么是这样?我的代码:

final class MyNode: ASDisplayNode {
    init() {
        self.backgroundColor = .red
        self.clipsToBounds = true
        self.cornerRadius = 10
        self.cornerRoundingType = .precomposited
    }

    ...
}

这只是创建一个没有圆角的矩形...

【问题讨论】:

  • 尝试删除这一行 self.cornerRoundingType = .precomposited
  • @aiwiguna 成功了!谢谢。这是为什么呢?
  • @aiwiguna 啊,但实际上显然存在与此相关的性能问题......

标签: ios swift textures asyncdisplaykit


【解决方案1】:

删除这一行

self.cornerRoundingType = .precomposited

我也不确定cornerRoundingType 预合成是如何工作的

在代码文档中说

* - ASCornerRoundingTypePrecomposited: corners are drawn using bezier paths to clip the content in a
 * CGContext / UIGraphicsContext. This requires .backgroundColor and .cornerRadius to be set. Use opaque
 * background colors when possible for optimal efficiency, but transparent colors are supported and much
 * more efficient than CALayer. The only limitation of this approach is that it cannot clip children, and
 * thus works best for ASImageNodes or containers showing a background around their children.
 *

回购issue也有人问这个问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-28
    • 2021-12-15
    • 2011-09-23
    • 1970-01-01
    • 1970-01-01
    • 2020-03-27
    • 1970-01-01
    • 2018-08-29
    相关资源
    最近更新 更多