我有一个带有动画,声音和webView的应用程序。动画由按钮触发,而另一个按钮触发到webView的segue。如果动画正在播放,当应用程序转向webView时,一旦应用程序向后移动,我将其设置为以便在点击播放按钮时动画重新开始。这很好用
但是,当动画暂停并且视图发生变化时,在返回主视图时,图像alpha和标签alpha似乎没有动画效果......尽管调试器说alpha正在适当改变,但没有任何内容出现屏幕。
如何在从WebView返回后点击播放时适当地设置动画?
这是播放按钮:
touch += 1
//define animated layers
imgLayer = firstImg.layer
labelLayer = firstLbl.layer
if touch == 1 {
print("touch = \(touch)")
self.firstImg.alpha = 0
self.firstLbl.text = ""
animateStart()
player.play()
self.playOut.setBackgroundImage(UIImage(named: "pause.png"), for: UIControlState.normal)
} else {
touch = 2
}
//toggle pause
if touch == 2 {
print("touch = \(touch)")
pause = !pause
if pause {
animatePause()
player.pause()
} else {
animateResume()
player.play()
}
}
}
和动画起始块:
func animateStart() {
print("animation started")
UIView.animate(withDuration: 4, animations: {
self.firstImg.alpha = 1
print("firstImg alpha = \(self.firstImg.alpha)")
self.firstImg.image = UIImage(named:"peter.JPG")
self.view.layoutIfNeeded()
}, completion: { finished in
if finished {
self.animateSecond()
}
})
}
这就是我如何解雇segue上的VC
func dismissVC() {
touch = 0
self.playOut.setBackgroundImage(UIImage(named: "playbtn.png"), for: UIControlState.normal)
player.stop()
initAudio()
self.dismiss(animated: true, completion: nil)
}