简体   繁体   English

iOS 7导航栏隐藏内容

[英]iOS 7 Navigation Bar Hiding Content

I have an app that was developed in iOS 6. But now in iOS 7 or even my app compiled for iOS 6, but running on an iOS 7 device the top navigation bar (the new giant one in iOS 7) my content is hidden. 我有一个在iOS 6中开发的应用程序。但是现在在iOS 7中,甚至我的应用程序都是针对iOS 6编译的,但是在iOS 7设备上运行顶部导航栏(iOS 7中新的巨型导航栏),我的内容被隐藏了。 The top navigation bar covers it. 顶部导航栏覆盖它。 If I manually move it down with CGRect it looks good in iOS 7, but now iOS 6 looks horrible (to much space above it). 如果我用CGRect手动向下移动它在iOS 7中看起来不错,但是现在iOS 6看起来很糟糕(在它上面的空间很大)。

The app was built with autolayout off because autolayout is way to difficult to get things setup correctly. 该应用程序是使用自动布局关闭构建的,因为自动布局是难以正确设置的方法。

My question is, is there an easy way to move the content down for iOS 7 only? 我的问题是,是否有一种简单的方法可以仅针对iOS 7移动内容? I really don't want to have to turn autolayout back on and spend a month trying to get all the UI elements back in place. 我真的不想重新开启自动布局,花一个月时间尝试将所有UI元素重新安装到位。 The app is pretty sophisticated with 30+ screens and a lot of animating view on screens. 该应用程序相当复杂,有30多个屏幕和屏幕上的大量动画视图。

I think there's still a little bit of misconception going around this layout problem even if iOS 7 was rolled out more than a year ago. 我认为即使iOS 7在一年多前推出,仍存在一些关于这种布局问题的误解。 So I eventually decided to elaborate further my answer. 所以我最终决定进一步阐述我的答案。

Here's the thing. 这就是事情。

Because automaticallyAdjustsScrollViewInsets ' default value is YES , a pretty straightforward solution could be adding the following code: 因为automaticallyAdjustsScrollViewInsets的默认值为YES ,所以一个非常简单的解决方案可能是添加以下代码:

if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) { // if iOS 7
    self.edgesForExtendedLayout = UIRectEdgeNone; //layout adjustements
}

into the ViewController's -viewDidLoad method. 进入ViewController的-viewDidLoad方法。

If you wish to remove the status bar quirk (due to the bar translucency, so it's not weird whatsoever) add self.navigationController.navigationBar.translucent = NO . 如果你想删除状态栏怪癖(由于条形半透明,所以它并不奇怪)添加self.navigationController.navigationBar.translucent = NO The default value is YES . 默认值为YES Note : this has nothing to do with the content, it's related to the content because of translucency but that's an altogether different story! 注意 :这与内容无关,因为半透明而与内容有关,但这是一个完全不同的故事!

Because extendedLayoutIncludesOpaqueBars is NO by default, self.navigationController.navigationBar.translucent = NO means basically having 因为extendedLayoutIncludesOpaqueBars默认为NOself.navigationController.navigationBar.translucent = NO表示基本上有

self.edgesForExtendedLayout = UIRectEdgeLeft | UIRectEdgeRight| UIRectEdgeBottom; 

Or, more generally, something like that (it's like pseudocode to give an idea...) 或者,更一般地说,类似的东西(它就像伪代码一样提出想法......)

BOOL enableTopEdge =  extendedLayoutIncludesOpaqueBars && !navigationBarIsTranslucent
self.edgesForExtendedLayout = (enableTopEdge & UIRectEdgeTop) | UIRectEdgeLeft | UIRectEdgeRight | UIRectEdgeBottom; 

You can also try setting the navigationBar.translucent = NO , as was mentioned in this answer . 您也可以尝试设置navigationBar.translucent = NO ,如本答案中所述

To hide the navigation bar , add the following to your UIViewController: 隐藏导航栏 ,请将以下内容添加到UIViewController:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    // Hide the top navigation bar.
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    self.navigationController.navigationBar.translucent = YES;
}

To show the navigation bar , use the following: 显示导航栏 ,请使用以下命令:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    // Show the top navigation bar.
    self.navigationController.navigationBar.translucent = NO;
}

Below are the results on iOS7: 以下是iOS7上的结果:

导航栏被隐藏。显示导航栏。

The screenshot on the left is with navigation bar hidden, while the image on the right is with navigation bar displayed - the contents of the table are correctly hidden under the navigation bar. 左侧的屏幕截图隐藏了导航栏,而右侧的图像显示了导航栏 - 表格内容正确隐藏在导航栏下方。

Hope this helps! 希望这可以帮助!

Put self.edgesForExtendedLayout = UIRectEdgeNone; 把self.edgesForExtendedLayout = UIRectEdgeNone;

in your ViewDidLoad method 在您的ViewDidLoad方法中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM