Calling layoutsubviews should not interrupt an existing transition
Currently, if you call layoutsubviews while the button is animating, setStyle(buttonStyle, animated: false) will be called and hence the animation will complete instantly.
Since my button animates the view it is in, layoutsubviews is called several times during the transition and hence the button doesn't work.
@email4nickp when you tell you call the layoutsubviews you mean the setNeedsLayout() method?
It works fine with the example project. Can you send me an example?
func styleDidSelected(style: DynamicButton.Style) {
dynamicButton.setStyle(style, animated: true)
animating = true
_ = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self.animationOver),userInfo: nil, repeats: false)
_ = Timer.scheduledTimer(timeInterval: 0.01, target: self, selector: #selector(self.layoutView),userInfo: nil, repeats: false)
}
var animating = false
func animationOver() {
animating = false
}
func layoutView() {
self.dynamicButton.layoutSubviews()
if (animating) {
_ = Timer.scheduledTimer(timeInterval: 0.01, target: self, selector: #selector(self.layoutView),userInfo: nil, repeats: false)
}
}
I know this is very hackish code, but it emulates what is occurring with my issue. Copy it into the example project's viewcontroller.
I'm using the SWRevealViewController in my project and this button animates the reveal of the rear controller. During this animation, the view containing the dynamic button has layoutSubviews() called multiple times during the animation.
Any update on this?