【问题标题】:IOS12 Flip TransitionWith: not working properlyIOS 12 翻转过渡宽度:无法正常工作
【发布时间】:2019-03-26 08:45:35
【问题描述】:

在开发一个重型 UI 应用程序时,QA 团队向我报告说,我们的视图“翻转”停止正常工作。 Aster 测试问题 我们注意到此问题仅适用于 IOS12。

如果您测试我添加的代码,即使是非常简单的示例,其中两个视图只有背景颜色,您也会在transitionWith 中看到:正在显示的视图不是动画的,只是被隐藏了。被隐藏的视图被正确地动画化了。

同样,这只是 IOS12 中的一个问题,在 transitionFrom:To: 中可以正常工作

class ViewController: UIViewController {

    var firstView: UIView!
    var secondView: UIView!
    var containerView: UIView!

    var showBackView = false

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        //containerView = UIView(frame: CGRect(x: 32, y: 32, width: 128, height: 128)) - // transitionFrom:To Code

        // General code
        firstView = UIView(frame: CGRect(x: 32, y: 32, width: 128, height: 128))
        secondView = UIView(frame: CGRect(x: 32, y: 32, width: 128, height: 128))

        firstView.backgroundColor = UIColor.red
        secondView.backgroundColor = UIColor.blue


        // transitionFrom:To Code
//        containerView.addSubview(firstView)
//        containerView.addSubview(secondView)
//        view.addSubview(containerView)


        // transitionWith: Code
        view.addSubview(firstView)
        view.addSubview(secondView)

        self.firstView.isHidden = false
        self.secondView.isHidden = true

        // General code
        let button = UIButton(frame: CGRect(x: 200, y: 200, width: 50, height: 50))
        button.addTarget(self, action: #selector(tappedButton), for: .touchUpInside)
        button.backgroundColor = UIColor.green
        view.addSubview(button)

    }

    @objc func tappedButton(sender: UIButton!) {
        flip()
    }

    func flip() {
        let transitionOptions: UIView.AnimationOptions = [.transitionFlipFromRight, .showHideTransitionViews]
        // transitionFrom:To Code
//        let toView = showBackView ? firstView : secondView
//        let fromView = showBackView ? secondView : firstView
//        UIView.transition(from: fromView!, to: toView!, duration: 1.0, options: transitionOptions, completion: nil)

        // transitionWith: Code
        print("******************")
        UIView.transition(with: firstView, duration: 3.0, options: transitionOptions, animations: {
            print(self.firstView.isHidden)
            print(self.secondView.isHidden)
            self.firstView.isHidden = !self.firstView.isHidden
        })

        print("----------------------")
        UIView.transition(with: secondView, duration: 3.0, options: transitionOptions, animations: {
            print(self.firstView.isHidden)
            print(self.secondView.isHidden)
            self.secondView.isHidden = !self.secondView.isHidden
        })
    }
}

这是一个已知问题吗?我在网上找不到任何参考资料;不幸的是,这会破坏旧动画。

【问题讨论】:

  • 我已经通过使用 transitionFrom:To: 解决了这个问题,但这不是解决方案,这是一种解决方法。 transitionWith:在 IOS12 上仍然刹车!

标签: ios swift uiviewanimationtransition ios12 apple-developer


【解决方案1】:

我已经通过使用 transitionFrom:To: 解决了这个问题,但这不是解决方案,这是一种解决方法。 transitionWith:仍然在 IOS12 上刹车!

【讨论】:

  • 您找到了任何解决方案。我在 ios15 中使用相同的代码并面临问题
猜你喜欢
  • 1970-01-01
  • 2016-07-23
  • 2014-11-29
  • 2016-02-05
  • 1970-01-01
  • 2019-05-15
  • 2020-10-29
  • 2014-01-13
  • 1970-01-01
相关资源
最近更新 更多