2016-01-05 66 views
1

Hello社區我只是想動畫一個UIView完全是一個UIButton。但它真的不適合我。使用Autolayout與Swift動畫UIButton

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

這就是我的代碼的樣子。

+0

漏下'self.view.needsUpdateConstraints()',它應該工作。如果你用'self.view.setNeedsUpdateConstraints()'替換它,那麼你一定不要調用這個方法。 – borchero

回答

0

=>嘗試這一個: -

UIView.animateWithDuration(0.6, 動畫: { self.button.transform = CGAffineTransformMakeScale(0.6,0.6)

},

completion: { 

    UIView.animateWithDuration(0.6){ 

     self.button.transform = CGAffineTransformIdentity 
    } 
}) 

=>如果您想用彈簧動畫更多彈跳效果:-

=> tr y folowing code:

@IBOutlet weak var button:UIButton!

@IBAction FUNC animateButton(發件人: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() } 
) 
} 
0

這真是瘋了,但人請務必設置正確的約束,這將幫助你。

它應該有一些像這樣工作

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

刪除self.view.needsUpdateConstraints()