UINavigationController 中的 UITableView 旋转后进入导航栏

标签 uitableview uinavigationcontroller rotation bounds

这是肖像:

alt text

这是风景

alt text

我已经尝试过轮换但没有成功:

self.tableView.autoresizesSubviews = YES;
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

最佳答案

我最近遇到了这个问题。就我而言,这是因为我正在执行导航 Controller 的旋转,该导航 Controller 不是应用程序窗口的根 Controller 。因此,我使用旋转通知监听器/仿射变换/边界调整方法来更改导航 Controller 的布局。这一切正常,但产生了此处描述的结果。我花了一段时间才注意到,当我旋转到横向时,导航栏的高度没有正确调整大小(即,从 44 像素到 32 像素,横向模式下框架的高度降低)。我的应用程序的根 View Controller 回复 willRotateToInterfaceOrientation didRotateFromInterfaceOrientation , 然而。该 View Controller 也已经知道关联的导航 Controller 。我通过将以下代码添加到 解决了这个问题willRotateToInterfaceOrientation 方法:

CGRect frame = self.navViewController.navigationBar.frame;
if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
    frame.size.height = 44;
} else {
    frame.size.height = 32;
}
self.navViewController.navigationBar.frame = frame;

希望这可以在类似情况下为某人节省一些时间。

关于UINavigationController 中的 UITableView 旋转后进入导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1882107/

相关文章:

ios - UITableViewCell 中的多行 UILabel 在 iOS8 中使用 autoLayout 给出错误的高度

ios - 以编程方式选择 TableView 单元格 : selectRowAtIndexPath vs setSelected

ios - GADBannerView 固定在 UITableViewController 中的屏幕底部

ios - 使用 Storyboard 中的按钮在 NavigationController 中嵌入的 View 之间导航

python - 图像旋转后像素值改变

ios - Swift UITableViewCell 阴影不出现

iOS 13 导航栏提示始终为黑色

iphone - 在带有 Storyboard 的 XCode 4 中以模态方式推送 View 时出现 "Unbalanced calls to begin/end appearance transitions"警告

javascript - 在 snap.svg 中使用 Matrix.rotate 旋转对象会使对象变形

javascript - 如何在jquery中使用css的旋转方法