shashankpali / EZYGradientView

Create gradients and blur gradients without a single line of code
MIT License
376 stars 43 forks source link

Gradient not updating on orientation change. #5

Open shshalom opened 8 years ago

shshalom commented 8 years ago

I have set EZYGradientView in interface builder, in portrait mode, but when I change the orientation to landscape the gradient does not update.

mouness2020 commented 7 years ago

yes same problem here gradient bounds not updated after changing screen orientation

ibrahimtall commented 7 years ago

Same here. Updating height constraints of the gradient view gives me white space on the extended parts.

mouness2020 commented 7 years ago

I used this library https://github.com/soffes/GradientView and add this line to fix the problem
gradientView.autoresizingMask = [.flexibleWidth, .flexibleHeight] i don't know if this line solve the problem in this library

ibrahimtall commented 7 years ago

Thanks. Will try it. Tried the autoresizingMask on this one and it does not work.

update For this one. Putting the gradientView function in "viewWillLayoutSubviews" seems to do the trick. The gradient view is rebuilt with the new frame being transitioned to.

anupam57 commented 7 years ago

Try this, it worked for me

override open func layoutSubviews() {
    super.layoutSubviews() 
    blurLayer?.frame = self.frame
    gradientLayer?.frame = self.frame
}
fonesti commented 7 years ago

To get a smooth orientation change animation the CAGradientLayer should be used as the UIView backing layer.

This is my solution with Swift 4:

import EZYGradientView

@IBDesignable
open class _EZYGradientView: EZYGradientView
{
    public required init?(coder aDecoder: NSCoder)
    {
        super.init(coder: aDecoder)
        self.gradientLayer = self.layer as? CAGradientLayer
    }

    override open func draw(_ rect: CGRect) {
        if self.gradientLayer == nil {
            self.gradientLayer = self.layer as? CAGradientLayer
        }
        super.draw(rect)
    }

    override open class var layerClass: Swift.AnyClass {
        get {
            return CAGradientLayer.self
        }
    }
}

Problem is well explained here: https://stackoverflow.com/questions/17555986/cagradientlayer-not-resizing-nicely-tearing-on-rotation-video-of-issue-attac