2016-02-12 98 views
0

我有一个非常简单的项目,我想在标签上设置右边距的动画,但是当我尝试它时,它会立即完成。NSLayoutConstraint动画立即完成

@IBAction func onDo(sender:UIButton) 
{ 
    self.view.setNeedsLayout() 
    self.testConstraint.constant = 40.0 

    UIView.animateWithDuration(2.0, animations: {() -> Void in 

     self.view.setNeedsLayout() 

     }) { (complete:Bool) -> Void in 

    } 
} 

该项目是在这里:

https://www.dropbox.com/s/9a0v0906riunkww/test2222.zip?dl=0

我失去了一些东西明显?

更新#1

看来它与UILabels一个问题而言,标准的UIView,或UIButton的动画罚款....有啥错一个UILabel?

更新#2

如果我设置的UILabel视图内容模式为中心,然后它工作正常,但它看起来并不很流畅......很奇怪。

+0

呼叫更换self.view.setNeedsLayout()'layoutIfNeeded()','不setNeedsLayout()' – dan

+0

我已经试过,在测试项目,它跳跃太:-( – Chris

+0

这很奇怪,这里有一些想法http://stackoverflow.com/q/17360402/2683201 –

回答

0

我可能在这里没有标记,但它看起来像我的动画程序只是setNeedslayout,这将导致屏幕立即重绘。你需要改变一些UIView的动画参数,以便看到某些动作。像self.view.frame,也许。 UIView的动画特性列表为here

0

尝试在动画关闭与self.view.layoutIfNeeded()

@IBAction func onDo(sender:UIButton) { 
    self.testConstraint.constant = 40.0 

    UIView.animateWithDuration(2.0, animations: {() -> Void in 

     self.view.layoutIfNeeded() 

     }) { (complete:Bool) -> Void in 

    } 
}