【问题标题】:Animating UIView - Stuck in Recursive Animation Loop: Swift动画 UIView - 陷入递归动画循环:Swift
【发布时间】: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


    【解决方案1】:

    查看文档后,我发现使用 animateWithDuration 会暂时禁用用户对动画视图的交互。如果要启用用户交互,则必须在 options 参数中设置 UIViewAnimationOptionAllowUserInteraction 常量。

    【讨论】:

    • 这个答案绝对是惊人的。谢谢你,泰勒!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多