简体   繁体   English

是否有必要在旋转时更新 TableView 布局?

[英]Is it necessary to update the TableView layout on rotation?

When using a collectionView on the iPad and rotating it, I call:在 iPad 上使用collectionViewrotating它时,我调用:

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)

    collectionView.collectionViewLayout.invalidateLayout()
}

Is it necessary to do the same thing with a tableView ?是否有必要对tableView做同样的事情?

I got the below code from this older answer我从这个较旧的答案中得到了以下代码

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)

    tableView.beginUpdates()
    tableView.endUpdates()
}

You don't need update layout when you rotation device.旋转设备时不需要更新布局。 Because tableView will auto adjust cell layout when rotation.因为 tableView 会在旋转时自动调整单元格布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM