带有 : not working properly 的 IOS 12 翻转过渡

标签 ios swift uiviewanimationtransition ios12 apple-developer

在开发重型 UI 应用程序时,QA 团队向我报告说我们 View 的“翻转”功能已停止正常工作。 Aster testing the issue 我们注意到这个 Issue 只针对 IOS12。

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

同样,这只是 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 上仍然刹车!

关于带有 : not working properly 的 IOS 12 翻转过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52926574/

相关文章:

ios - 有完整的pagecurl吗?更新

iphone - 如何制作我正在编写的 2 个应用程序交换信息?

iphone - 使用 OpenGL 在 iPad 上从整数数据集中绘制图像数据

ios - Objective-C:如何禁用 UIScrollView 中的垂直滚动

ios - 如何将 View 固定到屏幕边缘?

swift - didReceiveAuthenticationChallenge 委托(delegate)未在 Swift 中被调用

ios - Tableview 圆角未显示在底部

swift - 如何覆盖私有(private) init

ios - 如何在 iOS 7 上像 iPad appstore 一样进行 View 转换

ios - UIView setAnimationTransition 仅有时有效但并非总是有效?