UINavigationController 中的 UITableView 旋转后进入导航栏 [英] UITableView in UINavigationController gets under Navigation Bar after rotation

查看:59
本文介绍了UINavigationController 中的 UITableView 旋转后进入导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是肖像:

这是风景

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

I've tried this on rotation with no success:

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

推荐答案

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

I ran into this problem recently. In my case, it was because I was performing rotations of a navigation controller that was not the root controller of the application window. I was therefore using the rotate notification listener/affine transform/bounds adjustment approach to changing the layout of the navigation controller. This worked all right but produced the results described here. It took me a while to notice that when I rotated to landscape the nav bar's height was not being correctly resized (i.e., from 44 to 32 pixels, the framework's reduced height for landscape mode). The root view controller of my app was responding to willRotateToInterfaceOrientation and didRotateFromInterfaceOrientation, however. That view controller also already knew about the associated navigation controller. I remedied the problem by adding the following code to the willRotateToInterfaceOrientation method:

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;

希望这可以为遇到类似情况的人节省一些时间.

Hope this saves somebody some time in a similar situation.

这篇关于UINavigationController 中的 UITableView 旋转后进入导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆