Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradient not updating on orientation change. #5

Open
shshalom opened this issue Nov 9, 2016 · 6 comments
Open

Gradient not updating on orientation change. #5

shshalom opened this issue Nov 9, 2016 · 6 comments

Comments

@shshalom
Copy link

shshalom commented Nov 9, 2016

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

@mouness2020
Copy link

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

@ibrahimtall
Copy link

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

@mouness2020
Copy link

mouness2020 commented Feb 14, 2017

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
Copy link

ibrahimtall commented Feb 14, 2017

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
Copy link

anupam57 commented May 3, 2017

Try this, it worked for me

override open func layoutSubviews() {
    super.layoutSubviews() 
    blurLayer?.frame = self.frame
    gradientLayer?.frame = self.frame
}

@fonesti
Copy link

fonesti commented Jul 6, 2017

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

satishVekariya added a commit to satishVekariya/EZYGradientView that referenced this issue Feb 20, 2018
- Replace Backing layer class with CAGradientLayer class
- Remove layer creation and insertion 
- Fix shashankpali#5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants