2017-01-08 30 views
0

我有一个nslayoutconstraint,当用户按下按钮时,约束应该慢慢达到零。目前它只是在按下按钮时自动快速达到零。我的代码不起作用。这里是。慢动画动作

@IBAction func Expansion(_ sender: AnyObject) { 

    UIView.animate(withDuration: 0.1, animations: { 

     self.ScrolliewTopConstraint.constant = 0 
     self.ScrollView.isScrollEnabled = true 

    }, completion: nil) 
} 

回答

2

您需要在设置常量后设置动画。

// set the constant 
UIView.animate(withDuration: 0.1 { 
    self.view.layoutIfNeeded() 
} 
+0

你是什么意思 – user7222919

+0

我已经设定常数 – user7222919

+0

将其设置动画之前。然后动画'layoutIfNeeded()'。 – Mundi