【发布时间】:2016-03-15 05:50:15
【问题描述】:
我陷入了动画循环。我有一个名为 [stopBtn] 的按钮和一个名为 [backgroundView] 的 UIView。我想从加载 ViewController 到销毁它的时间为 UIView 的背景颜色设置动画。在viewDidAppear 函数中,我通过写animateView() 开始脉动
func animateView(){
UIView.animateWithDuration(1.0, animations: {
self.backgroundView.backgroundColor = UIColor.blackColor()
self.view.bringSubviewToFront(self.stopBtn)
}, completion: {
(Completed: Bool) -> Void in
UIView.animateWithDuration(1.0, delay: 0, options: UIViewAnimationOptions.CurveLinear, animations: {
self.backgroundView.backgroundColor = UIColor(red: 39, green: 117, blue: 0, alpha: 1)
self.view.bringSubviewToFront(self.stopBtn)
}, completion: {
(Completed : Bool) -> Void in
self.animateView()
})
})
}
@IBAction func stopBtnPressed(sender: UIButton) {
print("pressed")
}
我的问题是为什么我的stopBtn 不起作用?我已经知道它卡在循环中,这就是为什么我想帮助正确地制作动画(可能在另一个线程或其他东西上并保持主线程打开)。
stopBtn 连接到 Storyboard 中的另一个 ViewController。我曾尝试创建 IBAction,但没有成功。我还尝试将stopBtn 带到子视图[self.view.bringSubviewToFront(self.stopBtn)] 的前面。
【问题讨论】:
标签: swift uiview uianimation