0
我試圖使一個按鈕在視圖中的反彈效果會出現。我希望我的按鈕做這樣的事情如何使一個按鈕的反彈效果
How to create a UIView bounce animation?
我與此代碼這樣做,但它不是液...
UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: [], animations: ({
self.image.center.y = self.view.frame.height/4
}), completion: nil)
UIView.animateWithDuration(0.7, delay: 0.2, usingSpringWithDamping: 1, initialSpringVelocity: 0.8, options: [], animations: ({
self.image.center.y = self.view.frame.height/6
}), completion: nil)
UIView.animateWithDuration(0.9, delay: 0.4, usingSpringWithDamping: 1, initialSpringVelocity: 0.6, options: [], animations: ({
self.image.center.y = self.view.frame.height/4
}), completion: nil)
UIView.animateWithDuration(1, delay: 0.6, usingSpringWithDamping: 1, initialSpringVelocity: 0.4, options: [], animations: ({
self.image.center.y = self.view.frame.height/5.5
}), completion: nil)
UIView.animateWithDuration(1.05, delay: 0.8, usingSpringWithDamping: 1, initialSpringVelocity: 0.2, options: [], animations: ({
self.image.center.y = self.view.frame.height/4
}), completion: nil)
by fluid你的意思是不是連續發生? –
你可以使用UIView類的方法「+ animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:」 – WhiteTiger
有很多方法可以做到這一點。 @memmons在你發佈的帖子中的回答顯示了使用UIKit Dynamics來做這件事的一個很好的方法,但是你不使用它。爲什麼不嘗試呢?或者,您可以使用UIView關鍵幀動畫(使用animateKeyframesWithDuration:delay:options:animations:completion:'和/或animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:'方法顯示的UIKit Dynamics方法似乎是最適合你的效果,他提供的工作代碼告訴你如何使用它。 –