i am trying to animate my unbutton with a constraint and the animation is not working

痞子三分冷 提交于 2020-01-17 07:25:06

问题


Can some one please tell me why this is not animating? I feel that the code is all perfect but the animate function is not working. The button is jumping instantly from side to side but like i said it isn't animating...

func moveResetButton( constraint : NSLayoutConstraint, isOffScreen : Bool)  {

    if isOffScreen {
        //animate the button onto the screen
        UIView.animate(withDuration: 3.0, delay: 0.0, options: .curveLinear, animations: {

            constraint.constant += 120

        }, completion: nil)

    } else {
        //animate the button off of the screen
        UIView.animate(withDuration: 1.0, delay: 0.0, options: .curveLinear, animations: {

            constraint.constant -= 120

        }, completion: nil)
    }
}

回答1:


i figured it out. just need to add self.view.layoutIfNeeded() to the code under the constraint change. worked smoothly.



来源:https://stackoverflow.com/questions/43647445/i-am-trying-to-animate-my-unbutton-with-a-constraint-and-the-animation-is-not-wo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!