在使用swift 3的Xcode 8中,我有2個函數。當「HideButton」函數被調用時,它會執行正確的淡出動畫,但是當調用「ShowButton」函數時,淡入動畫不會發生。 「ShowButton」動畫功能有什麼問題,我該如何解決?我怎樣才能使一個按鈕淡出動畫,然後使用swift淡入功能3
func HideButton() {
UIView.animate(withDuration: 0.2, delay: 0, animations: {
self.MainButton.alpha = 0
}, completion: { finished in
self.MainButton.isHidden = true
})
Timer.scheduledTimer(timeInterval: 1.2, target: self, selector: #selector(GameViewController.ShowButton), userInfo: nil, repeats: false)
}
func ShowButton() {
UIView.animate(withDuration: 0.2, delay: 0, animations: {
self.MainButton.alpha = 1
}, completion: { finished in
self.MainButton.isHidden = false
})
Timer.scheduledTimer(timeInterval: 1.2, target: self, selector: #selector(GameViewController.HideButton), userInfo: nil, repeats: false)
}
[動畫顯示按鈕]的可能重複(http://stackoverflow.com/questions/41466952/animated-display-button) – matt
刪除提及'isHidden'的所有行。完成。 – matt