为什么推送另一个视图控制器的动画不流畅?
Why the animation of push another view controller goes not smooth?
我在每个单元格上都有一个 table 视图和集合视图。
当我点击单元格时,将在单元格的 didSelectRowAt:IndexPath
方法中调用以下代码。
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
navigationController?.pushViewController(anotherViewController(), animated: true)
}
anotherViewController
目前是 Storyboard 上的空视图控制器。它只在 viewDidLoad()
.
中打印 "I'm coming"
这是问题所在:
当我触摸单元格时,推送动画似乎卡住了,请查看以下GIF。
我真的对发生的事情感到困惑。
随时提供任何建议。
下图显示了视图层次结构。
table 视图中的单元格。
单元格内容视图上的集合视图和其他组件。
最后,集合视图的内容视图上的图像视图。
我怀疑问题出在 anotherViewController()
参考文献中。当我推送到 UIViewController
实例时,我什至能够重现该问题:
navigationController?.pushViewController(UIViewController(), animated: true)
但是当我从情节提要中实例化一个场景时,效果很好。显然,您需要一个具有适当故事板标识符的场景:
let controller = storyboard!.instantiateViewController(withIdentifier: "Details")
navigationController?.pushViewController(controller, animated: true)
或者,如果我在两个视图控制器之间定义了 segue 并执行了 segue,那也有效:
performSegue(withIdentifier: "DetailsSegue", sender: self)
我的解决方案是显式设置新视图控制器的背景颜色,即使它是黑色。
我有同样的问题,因为我没有使用情节提要,这就是我的解决方案。
我在每个单元格上都有一个 table 视图和集合视图。
当我点击单元格时,将在单元格的 didSelectRowAt:IndexPath
方法中调用以下代码。
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
navigationController?.pushViewController(anotherViewController(), animated: true)
}
anotherViewController
目前是 Storyboard 上的空视图控制器。它只在 viewDidLoad()
.
中打印 "I'm coming"
这是问题所在:
当我触摸单元格时,推送动画似乎卡住了,请查看以下GIF。
我真的对发生的事情感到困惑。
随时提供任何建议。
下图显示了视图层次结构。
table 视图中的单元格。
单元格内容视图上的集合视图和其他组件。
最后,集合视图的内容视图上的图像视图。
我怀疑问题出在 anotherViewController()
参考文献中。当我推送到 UIViewController
实例时,我什至能够重现该问题:
navigationController?.pushViewController(UIViewController(), animated: true)
但是当我从情节提要中实例化一个场景时,效果很好。显然,您需要一个具有适当故事板标识符的场景:
let controller = storyboard!.instantiateViewController(withIdentifier: "Details")
navigationController?.pushViewController(controller, animated: true)
或者,如果我在两个视图控制器之间定义了 segue 并执行了 segue,那也有效:
performSegue(withIdentifier: "DetailsSegue", sender: self)
我的解决方案是显式设置新视图控制器的背景颜色,即使它是黑色。 我有同样的问题,因为我没有使用情节提要,这就是我的解决方案。