iPhone 纵向导航栏高度仍然较短
我的应用程序的根视图控制器支持任何方向,但用户可以导航到另一个仅支持横向方向的视图控制器。
基本问题是,无论设备的实际物理方向如何,当用户弹回到根视图控制器时,导航栏的高度都适合横向模式。我想弄清楚如何让导航栏以 44(纵向高度)而不是 32(横向高度)的高度出现。
尽管导航栏未设置为正确的高度,但根视图控制器的 UITableView 已正确偏移(距屏幕顶部 44 像素)。
在第二个视图控制器的 -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];
}
因为这个辅助视图控制器允许导航到从属视图控制器(以及弹出回根视图控制器),所以我将以下内容添加到 -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];
}
感谢有关如何强制重新计算导航栏高度的任何建议。
My app's root view controller supports any orientation but user can navigate to another view controller that supports only landscape orientation.
The basic problem is that regardless of the device's actual physical orientation, when the user pops back to root view controller, the navigation bar has a height that would be appropriate for landscape mode. I would like to figure out how to get navigation bar to appear with height of 44 (portrait height) instead of 32 (landscape height).
Although the navigation bar is not set to proper height, the root view controller's UITableView is offset correctly (44 pixels from top of screen).
Inside the second view controller's -viewWillAppear: I perform the standard rotational transform:
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];
}
Because this secondary view controller allows navigation to subordinate view controllers (as well as popping back up to root view controller), I have added the following to -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];
}
Thanks for any advice on how to force recalculation of navigation bar height.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定是否有更好的方法,但这有效:
基本上,隐藏导航栏,弹出视图控制器并显示导航栏。某处的一些代码调整了导航栏的高度,一切都很好。
Not sure if there's a better way, but this worked:
Basically, hide the nav bar, pop the view controller and the show the nav bar. Some code somewhere adjusts the nav bar height and everything's fine.