从动画中排除工具栏

时间:2019-05-05 15:43:04

标签: ios swift

我有以下代码:

@IBOutlet weak var toolbar: UIToolbar!


@IBAction func buttonHamburgerTapped(_ sender: Any) {
    let color = UIColor(red: 0/255, green: 116/255, blue: 189/255, alpha: 1)

    if !buttonHamburgerIsVisible {
        toolbar.setItems([hamburger], animated: true)
        leading.constant = 330
        trailing.constant = -330
        hamburger.tintColor = color
        buttonHamburgerIsVisible = true
        UIView.animate(withDuration: 0.25, delay: 0.0, options: .curveEaseInOut, animations: {
            self.view.layoutIfNeeded()
        })
    } else {
        toolbar.setItems([hamburger, flexOne, buttonAdd, flexTwo, barButtonTimeline], animated: false)
        leading.constant = 0
        trailing.constant = 0
        hamburger.tintColor = UIColor.white
        buttonHamburgerIsVisible = false
        UIView.animate(withDuration: 0.25, delay: 0.0, options: .curveEaseInOut, animations: {
            self.view.layoutIfNeeded()
        })
    }
}

要解释这个问题-我有一个mainView和secondView。 MainView位于secondView的顶部。调用该函数时,mainView将移动到动画支持的右侧。如您所见,此动画在if {...}else {...}的结尾处调用。

问题在于工具栏也正在设置动画(从左轻松移动),这是不应该的。删除以下代码段将删除工具栏上不需要的动画,但是mainView和secondView的过渡动画也将被删除:

UIView.animate(withDuration: 0.25, delay: 0.0, options: .curveEaseInOut, animations: {
            self.view.layoutIfNeeded()
        })

如何从代码稍后调用的动画中排除工具栏?

0 个答案:

没有答案