iPhone 纵向导航栏高度仍然较短

标签 iphone rotation uinavigationbar transform orientation

我的应用程序的 Root View Controller 支持任何方向,但用户可以导航到另一个仅支持横向方向的 View Controller 。

基本问题是,无论设备的实际物理方向如何,当用户弹回 Root View Controller 时,导航栏的高度都适合横向模式。我想弄清楚如何让导航栏以 44(纵向高度)而不是 32(横向高度)的高度显示。

虽然导航栏未设置为正确的高度,但 Root View Controller 的 UITableView 已正确偏移(距屏幕顶部 44 像素)。

在第二个 View Controller 的 -viewWillAppear 内:我执行标准旋转变换:

if (deviceOrientation == UIDeviceOrientationPortrait)
   {
   UIScreen *screen = [UIScreen mainScreen];
   CGFloat screenWidth = screen.bounds.size.width;
   CGFloat screenHeight = screen.bounds.size.height;
   UIView *navView = [[self navigationController] view];
   navView.bounds = CGRectMake(0, 0, screenHeight, screenWidth);
   navView.transform = CGAffineTransformIdentity;
   navView.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
   navView.center = CGPointMake(screenWidth/2.0, screenHeight/2.0);
   [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
   }

因为这个辅助 View Controller 允许导航到从属 View Controller (以及弹出回 Root View Controller ),所以我将以下内容添加到 -viewWillDisappear:

if (deviceOrientation == UIDeviceOrientationPortrait)
   {
   UIScreen *screen = [UIScreen mainScreen];
   CGFloat screenWidth = screen.bounds.size.width;
   CGFloat screenHeight = screen.bounds.size.height;
   UIView *navView = [[self navigationController] view];
   navView.bounds = CGRectMake(0, 0, screenWidth, screenHeight);
   navView.transform = CGAffineTransformIdentity;
   navView.center = CGPointMake(screenWidth/2.0, screenHeight/2.0);
   [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
   }

感谢您提供有关如何强制重新计算导航栏高度的建议。

最佳答案

不确定是否有更好的方法,但这有效:

[[self navigationController] setNavigationBarHidden:YES animated:NO];
[[self navigationController] popViewControllerAnimated:YES];
[[self navigationController] setNavigationBarHidden:NO animated:NO];

基本上,隐藏导航栏,弹出 View Controller 并显示导航栏。某处的一些代码调整了导航栏的高度,一切都很好。

关于iPhone 纵向导航栏高度仍然较短,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3339843/

相关文章:

iphone - 将 Xcode 项目移动到不同的计算机

android - Rajawali 旋转相机与 Sensor.TYPE_ROTATION_VECTOR 奇怪的行为

iphone - 单击 uitableview 中的单元格时如何获取下一个 View 上的单元格文本

iphone - 如何更改 uinavigationbar 后退按钮文本

ios7 - 向 UIToolBar/UINavigationBar/UITabBar 添加图层蒙版会破坏半透明

ios - 在 Objective-C 中使用 SCRecorder 以修改后的播放速度保存视频

iphone - 关闭 UIAlertView 中 UITextField 的键盘

iphone - 我的 Mac 上有什么 iOS 版本

java - 为什么我的围绕另一个点旋转一个点的方法不起作用?

swift - 有谁知道如何让这个泡泡射击游戏快速移动