使用Swift为Autolayout动画UIButton

时间:2016-01-05 17:51:53

标签: ios swift animation uiview autolayout

Hello Community我只是想让UIView完全为UIButton制作动画。但这对我来说真的不起作用。

 self.introConstraints.constant = self.view.frame.width
    self.view.needsUpdateConstraints()
    UIView.animateWithDuration(0.6){
        self.view.layoutIfNeeded()
    }

这就是我的代码的样子。

3 个答案:

答案 0 :(得分:0)

=>试试这个: -

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

},

completion: { 

    UIView.animateWithDuration(0.6){

        self.button.transform = CGAffineTransformIdentity
    }
})

=>如果你想用弹簧动画更多的弹跳效果。: -

=>尝试下面的代码:

@IBOutlet弱变量按钮:UIButton!

@IBAction func animateButton(sender:AnyObject){

    button.transform = CGAffineTransformMakeScale(0.6, 0.6)

   UIView.animateWithDuration(2.0,

   delay: 0,
   usingSpringWithDamping: CGFloat(0.20),

   initialSpringVelocity: CGFloat(6.0),

   options: UIViewAnimationOptions.AllowUserInteraction,

   animations: {

        self.button.transform = CGAffineTransformIdentity
   },
      completion: { Void in()  }
 )
}

答案 1 :(得分:0)

这真的很疯狂,但是大家确保你设置了正确的约束来帮助你。

它可以使用类似的东西

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

答案 2 :(得分:0)

删除self.view.needsUpdateConstraints()