在开发一个重型UI应用程序时,QA团队报告说,我们视图的“翻转”无法正常工作。Aster测试这个问题我们注意到这个问题只针对IOS12。
如果你测试我添加的代码,即使是非常简单的两个只有背景颜色的视图的例子,你也会在transitionWith中看到:正在显示的视图不是动画的,只是隐藏的。隐藏的视图正在正确地设置动画。
同样,这只是IOS12中的一个问题,在从:到:的转换中工作正常:
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
})
}
}这是一个已知的问题吗?我在网上找不到任何关于这个的参考资料;不幸的是,这破坏了旧的动画。
发布于 2018-11-29 14:50:27
我已经通过使用transitionFrom:To:解决了这个问题,但这不是一个解决方案,这是一个变通办法。transitionWith:仍然在IOS12上刹车!
https://stackoverflow.com/questions/52926574
复制相似问题