アニメーションが実行される前に私のラベルが消えています。ラベルが非表示になる前にUIViewのアニメーションが終了しない
ボタンを押してからアニメーションを実行し、ラベルとボタンをスライドさせます。しかし、私がボタンを押すと、アニメーションがそれらをスライドさせる前に両方とも隠されています。
func nextGame() {
UIView.animate(withDuration: 3, delay: 0.0, options: .allowAnimatedContent, animations: {
NSLog("Animation started")
self.labelWinningPlayer.center = CGPoint(x: self.labelWinningPlayer.center.x + 500, y: self.labelWinningPlayer.center.y)
self.buttonNextGameLabel.center = CGPoint(x: self.buttonNextGameLabel.center.x + 500, y: self.buttonNextGameLabel.center.y)
}, completion: { (finished: Bool) in
NSLog("Animation stopped")
self.labelWinningPlayer.isHidden = true
self.buttonNextGameLabel.isHidden = true
})
//sets buttons to start position
labelWinningPlayer.center = CGPoint(x: labelWinningPlayer.center.x - 1000, y: labelWinningPlayer.center.y)
buttonNextGameLabel.center = CGPoint(x: buttonNextGameLabel.center.x - 1000, y: buttonNextGameLabel.center.y)
//hides buttons that lay under the animated buttons
for i in 1...9 {
if let button = view.viewWithTag(i) as? UIButton {
button.setImage(nil, for: .normal)
}
}
activeGame = true
}
//animation should get started with this button
@IBAction func buttenNextGameAction(_ sender: Any) {
nextGame()
}
//slides buttons in
func slideNextGameButtons() {
labelWinningPlayer.isHidden = false
buttonNextGameLabel.isHidden = false
UIView.animate(withDuration: 0.5, animations: {
self.labelWinningPlayer.center = CGPoint(x: self.labelWinningPlayer.center.x + 500, y: self.labelWinningPlayer.center.y)
self.buttonNextGameLabel.center = CGPoint(x: self.buttonNextGameLabel.center.x + 500, y: self.buttonNextGameLabel.center.y)
})
}
ここにNSLogがあります。それによると、それは完全なアニメーションを実行しています...
2017-11-15 23:26:17.321465 [2442:245232] Animation started
2017-11-15 23:26:20.325137 [2442:245232] Animation stopped
おかげさまであなたの助けをありがとう!
にラベルとボタンのスーパービューclipsToBoundsプロパティを設定しますか? – matt
ラベルとボタンは自動レイアウト制約によって配置されていますか? – matt
アニメーションが終了すると、それらは非表示になります。また、自動レイアウトで配置されていないものはありません。 – Ravehorn