Ios 使用Swift自动布局为UIButton设置动画

Ios 使用Swift自动布局为UIButton设置动画,ios,swift,animation,uiview,autolayout,Ios,Swift,Animation,Uiview,Autolayout,大家好,社区,我只想给UIView设置动画,就是一个UIButton。但这对我来说真的不管用 self.introConstraints.constant = self.view.frame.width self.view.needsUpdateConstraints() UIView.animateWithDuration(0.6){ self.view.layoutIfNeeded() } 这就是我的代码的样子 =>试试这个:- UIView.an

大家好,社区,我只想给UIView设置动画,就是一个UIButton。但这对我来说真的不管用

 self.introConstraints.constant = self.view.frame.width
    self.view.needsUpdateConstraints()
    UIView.animateWithDuration(0.6){
        self.view.layoutIfNeeded()
    }
这就是我的代码的样子

=>试试这个:-

UIView.animateWithDuration(0.6, 动画: { self.button.transform=CGAffineTransformMakeScale(0.6,0.6)

},

=>如果希望通过弹簧动画获得更大的反弹效果:-

=>请尝试以下代码:

@IBVAR按钮:UIButton

@iAction func animateButton(发件人:AnyObject){

=>试试这个:-

UIView.animateWithDuration(0.6, 动画: { self.button.transform=CGAffineTransformMakeScale(0.6,0.6)

},

=>如果希望通过弹簧动画获得更大的反弹效果:-

=>请尝试以下代码:

@IBVAR按钮:UIButton

@iAction func animateButton(发件人:AnyObject){


这真的很疯狂,但是男人们确保你设置了正确的约束,这将帮助你

它应该和这样的东西一起工作

 self.startConstraints.constant = self.view.frame.width - self.startButton.frame.width
    UIView.animateWithDuration(0.6){
        self.view.layoutIfNeeded()
    }

这真的很疯狂,但是男人们确保你设置了正确的约束,这将帮助你

它应该和这样的东西一起工作

 self.startConstraints.constant = self.view.frame.width - self.startButton.frame.width
    UIView.animateWithDuration(0.6){
        self.view.layoutIfNeeded()
    }

删除self.view.needsUpdateConstraints()

删除self.view.needsUpdateConstraints()

省去
self.view.needsUpdateConstraints()
,它应该可以工作。如果用
self.view.setNeedsUpdateConstraints()替换该方法,则永远不能调用该方法
它也应该可以。省略
self.view.needsUpdateConstraints()
它应该可以工作。如果用
self.view.setNeedsUpdateConstraints()替换该方法,则永远不要调用该方法。
它也应该可以。
 self.startConstraints.constant = self.view.frame.width - self.startButton.frame.width
    UIView.animateWithDuration(0.6){
        self.view.layoutIfNeeded()
    }