Der Versuch, CAConstraints mit CALayer zu verwenden. Nach vielen Versuchen und Suchen kann ich es nicht zum Laufen bringen. Nach dem Drucken: Der Superlayer hat einen Rahmen (sichtbar mit Farbe), der Sublayer hat Beschränkungen, aber nichts wird gezeichnet (Sublayer hat 0 Frames).CALayer, CACstraints funktioniert nicht
Dies ist aus der 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()
}
Die Superlayer (blau), verhält sich ok, Ändern der Größe und alle. Die Unterschicht (rot), nichts.
Wenn ich den Sublayer-Rahmen einstelle, wird er gezeichnet, bleibt aber statisch.