Open shshalom opened 8 years ago
yes same problem here gradient bounds not updated after changing screen orientation
Same here. Updating height constraints of the gradient view gives me white space on the extended parts.
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
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.
Try this, it worked for me
override open func layoutSubviews() {
super.layoutSubviews()
blurLayer?.frame = self.frame
gradientLayer?.frame = self.frame
}
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
I have set EZYGradientView in interface builder, in portrait mode, but when I change the orientation to landscape the gradient does not update.