jul*_*adi 6 orientation uitableview ios swift ios11
我已经实现了iOS 11功能preferredsLargeTitles,并且效果很好。纵向模式按预期工作:
我知道大标题在横向模式下始终会保持折叠状态(小),这对我来说很好。问题是,当我尝试更改为横向然后再次更改为纵向时,默认情况下应以纵向模式将大标题扩展(大),但直到我向下滚动时才会显示:
我的代码看起来很简单:
if #available(iOS 11.0, *) {
  navigationController?.navigationBar.prefersLargeTitles = true
  navigationItem.largeTitleDisplayMode = .always
}
我还尝试在tableView.contentInsetAdjustmentBehavior上使用不同的值,但未进行任何更改。我现在通过在方向更改后以编程方式向下滚动表格来解决此问题,但是我认为这只是一种解决方法(不是很好)。
那应该能按预期工作吗?我的实现中还剩下什么吗?有更好的解决方法吗?
小智 6
我遇到了同样的问题。这对我有用。
    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        navigationItem.largeTitleDisplayMode = .always
        coordinator.animate(alongsideTransition: { (_) in
            self.coordinator?.navigationController.navigationBar.sizeToFit()
        }, completion: nil)
    }
一种方法是保存最大导航栏高度,并在旋转期间设置它。
像这样的东西:
var maximumHeight: CGFloat = 0
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)
        guard let navigationController = navigationController else {
            return
        }
        if maximumHeight < navigationController.navigationBar.frame.height {
            maximumHeight = navigationController.navigationBar.frame.height
        }
        coordinator.animate(alongsideTransition: { (_) in
            navigationController.navigationBar.frame.size.height = self.maximumHeight
        }, completion: nil)
}
在横向模式下,系统知道它必须改变其大小,因此您不必担心。
@rassar @twofish
| 归档时间: | 
 | 
| 查看次数: | 379 次 | 
| 最近记录: |