DynamicButton icon indicating copy to clipboard operation
DynamicButton copied to clipboard

Calling layoutsubviews should not interrupt an existing transition

Open nick-potts opened this issue 8 years ago • 3 comments

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.

nick-potts avatar Apr 19 '17 14:04 nick-potts

@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?

yannickl avatar Apr 24 '17 19:04 yannickl

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.

nick-potts avatar Apr 27 '17 02:04 nick-potts

Any update on this?

nick-potts avatar May 25 '17 10:05 nick-potts