【发布时间】:2019-06-02 17:41:41
【问题描述】:
我有两个视图控制器,A 和 B。我可以通过转场从 A 转到 B,并且我通过实现 UISegue 类在转场上实现了淡入动画。但是,在设备旋转和展开过程中会出现问题(从 B 到 A,而在 B 中发生了旋转)。
出现的问题是要呈现的视图(视图 A)的布局错误。在转换不起作用之前调用 setNeedsUpdateConstraints() 或 layoutSubviews() 之类的函数或类似函数。屏幕截图描述了以横向打开 A 然后执行到 B 的 segue 的情况。在 B 中时,设备会旋转回纵向并展开到 A。
转场的 Swift 代码:
class SegueFadeOut: UIStoryboardSegue {
override func perform() {
UIView.transition(from: source.view, to: destination.view, duration: 5.5, options: [.transitionCrossDissolve]) { (success) in
self.destination.dismiss(animated: false, completion: nil)
}
}
}
class SegueFadeIn: UIStoryboardSegue {
override func perform() {
let toViewController = self.destination
let fromViewController = self.source
let containerView = fromViewController.view.superview
toViewController.view.alpha = 0.0
containerView?.addSubview(toViewController.view)
UIView.animate(withDuration: 0.5, delay: 0, options: .curveEaseInOut, animations: {
toViewController.view.alpha = 1.0
}, completion: { success in
fromViewController.present(toViewController, animated: false, completion: nil)
})
}
}
关于如何或在何处实现解决此布局问题的功能的任何线索?谢谢!
【问题讨论】:
标签: ios iphone swift storyboard transition