ios – layerClass breaks auto layout


I made a custom view which has CAGradientLayer as a layer, and I added this view on the other view with bottom anchor. It was just very simple auto layout constraint with bottom, leading and height constraints, but the bottom constraint didn’t work, but it was always at the top(x == 0).

class GradientBlurView: UIView {
    override class var layerClass: AnyClass { CAGradientLayer.self }
}

I tried almost everything I could imagine and finally removed the layerClass and added the CAGradientLayer as a sublayer, and the constraint started working.

class GradientBlurView: UIView {
    private var gradientLayer =  CAGradientLayer()

...

    private func didLoad() {
        layer.addSublayer(gradientLayer)
    }
}

Is there anything I missed to override layerClass or it is kind of a bug?

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img