CALayerでCAConstraintsを使用しようとしています。多くの試みと検索の後、私はそれを働かせることはできません。印刷後:スーパーレイヤーにはフレーム(色で表示)があり、サブレイヤーには制約がありますが、何も描画されません(サブレイヤーにはフレームがありません)。 CALayer、CAConstraints not working
これは、NSViewController
override func viewDidAppear() {
super.viewDidAppear()
let layer = CALayer()
layer.backgroundColor = NSColor.red.cgColor
// centerView is just an NSView, first child of the main view.
self.centerView.wantsLayer = true
self.centerView.layer?.layoutManager = CAConstraintLayoutManager()
self.centerView.layer?.addSublayer(layer)
self.centerView.layer?.backgroundColor = NSColor.blue.cgColor
layer.addConstraint(CAConstraint(attribute: CAConstraintAttribute.midX, relativeTo: "superlayer", attribute: CAConstraintAttribute.midX))
layer.addConstraint(CAConstraint(attribute: CAConstraintAttribute.midY, relativeTo: "superlayer", attribute: CAConstraintAttribute.midY))
layer.addConstraint(CAConstraint(attribute: CAConstraintAttribute.width, relativeTo: "superlayer", attribute: CAConstraintAttribute.width))
layer.addConstraint(CAConstraint(attribute: CAConstraintAttribute.height, relativeTo: "superlayer", attribute: CAConstraintAttribute.height))
layer.setNeedsDisplay()
self.centerView.layer?.setNeedsDisplay()
}
スーパーレイヤ(青)からのものである、OK行動リサイズ、すべてされます。副層(赤)、何もない。
サブレイヤフレームを設定すると描画されますが、静止したままになります。