UINavigationController中的UITableView在轮换后获得导航栏

Jor*_*rge 3 rotation uitableview uinavigationcontroller bounds

这是肖像:

alt text http://i45.tinypic.com/2cp6ttf.jpg

这是风景

替代文字http://i47.tinypic.com/15g6ve9.jpg

我在轮换时试过这个但没有成功:

self.tableView.autoresizesSubviews = YES;
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
Run Code Online (Sandbox Code Playgroud)

jst*_*nco 13

我最近遇到了这个问题.在我的情况下,这是因为我正在执行不是应用程序窗口的根控制器的导航控制器的旋转.因此,我使用旋转通知侦听器/仿射变换/边界调整方法来更改导航控制器的布局.这很有效,但产生了这里描述的结果.我花了一段时间注意到,当我旋转到横向时,导航栏的高度没有被正确调整大小(即,从44到32像素,框架的横向模式的高度降低).我的应用程序的根视图控制器响应willRotateToInterfaceOrientationdidRotateFromInterfaceOrientation但是.该视图控制器也已经知道相关的导航控制器.我通过将以下代码添加到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;
Run Code Online (Sandbox Code Playgroud)

希望这可以节省一些类似情况的人.


小智 7

当以root身份使用自定义视图控制器(管理其他视图控制器本身)时,它负责将所有旋转事件转发到当前活动的子控制器(如果我可以这样调用它).这些事件是:

– willRotateToInterfaceOrientation:duration:

– willAnimateRotationToInterfaceOrientation:duration:

– didRotateFromInterfaceOrientation:

– willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:

– didAnimateFirstHalfOfRotationToInterfaceOrientation:

– willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:
Run Code Online (Sandbox Code Playgroud)

因此,对于由自定义根控制器管理的导航控制器,转发– willAnimateRotationToInterfaceOrientation:duration:到导航控制器可以在旋转时修复错误导航栏高度的问题.

  • 这是最干净的解决方案. (2认同)

cha*_*ndu 6

在didRotateFromInterfaceOrientation方法中添加以下行.

[self.navigationController.view layoutSubviews];

我希望这样做.