【问题标题】:UIView show/hide animation : hide animation does not seem to be workingUIView 显示/隐藏动画:隐藏动画似乎不起作用
【发布时间】:2021-04-24 12:39:25
【问题描述】:

我正在尝试实现UIView 动画效果,其中目标UIView 被触发以通过动画选项可见,并且在完成后返回到之前的隐藏状态。

下面是我写的代码,但是好像有问题。因为显示动画效果很好,但是当涉及到隐藏时,UIView 会立即消失,而不是有意隐藏动画效果。

我尝试将 options 参数更改为 hideConsentView(),但它并没有改变任何东西。

我错过了什么吗?

var consentStatusView = UIView() 

func showConsentStatusView() {
    UIView.transition(with: consentStatusView, duration: 1.0, options: .transitionCrossDissolve, animations: {
        self.consentStatusView.isHidden = false
    }, completion: { (finished) in
        self.hideConsentStatusView()
    })
}

func hideConsentStatusView() {
    UIView.transition(with: consentStatusView, duration: 1.0, options: .transitionCrossDissolve, animations: {
        self.consentStatusView.isHidden = true
    }, completion: nil)
}

【问题讨论】:

  • 似乎工作正常,代码中没有问题,请确保您没有设置 consentStatusView.isHidden = true 或从其他没有动画的代码中删除 consentStatusView

标签: ios swift animation uiview


【解决方案1】:

您可以简单地使用以下功能:

UIView.animate(withDuration: 0.3, animations: {
   self.consentStatusView.alpha = 0 //If you show a view alpha = 1
}) { (finished) in
   self.consentStatusView.isHidden = true //If you unHide your view isHidden = false
}

【讨论】:

    猜你喜欢
    • 2012-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-24
    • 2016-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多