关键词:
【中文标题】IOS7中的状态栏和导航栏问题【英文标题】:Status bar and navigation bar issue in IOS7 【发布时间】:2013-09-29 15:05:25 【问题描述】:我正在将我的应用程序迁移到 iOS 7。为了处理状态栏问题,我添加了此代码
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f)
CGRect frame = self.navigationController.view.frame;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
frame.origin.y = 20;
else
frame.origin.x = 20;
[self.navigationController.view setFrame:frame];
这在正常情况下工作正常。如果我正在改变方向(应用程序仅支持横向)或呈现任何视图控制器并关闭模型视图控制器,我的视图控制器对齐方式发生了变化。状态栏再次与我的视图控制器重叠。这段代码根本不起作用。请指导我解决此状态栏问题。
案例 2:这就是我展示视图控制器的方式
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
reader.supportedOrientationsMask = ZBarOrientationMaskLandscape;
else
reader.supportedOrientationsMask = ZBarOrientationMaskPortrait;
[self presentModalViewController:reader animated:YES];
参考:
提前致谢。
【问题讨论】:
正如我所提到的,如果方向改变状态栏超过圈的问题发生,甚至不单独存在模型视图控制器案例。 这里是这个问题的直接答案:***.com/questions/18775874/… 【参考方案1】:修复 IOS 7 中的状态栏问题
最后,我使用 xcode5 中的 delta value 属性修复了状态栏重叠问题。首先,我将原点 - y 20pxl 增加到 Xib 中使用的所有控制器(它似乎只在 IOS 7 中工作正常),之后我将所有视图控制器原点 -y 的增量值设置为 -20 它工作正常在 iOS 6 和 iOS 7 中。
执行此操作的步骤。
Xcode 5 提供预览选项,可根据操作系统版本在不同视图中查看 xib 的外观。
从助理编辑器中选择预览选项
点击助手编辑器
并选择预览选项以预览不同版本的选定视图控制器。
视图控制器视图预览选项。
在预览中,您可以找到切换选项以预览不同版本的视图。在预览中,如果没有通过切换版本正确修复,您可以清楚地感受到状态栏问题。
解决状态栏问题的三个步骤: 第 1 步:确保文件检查器中的视图针对我们 7.0 及更高版本。
第 2 步:将视图控制器中添加的所有控件的原点 - y 增加 20 像素(正好是状态栏的大小)。
第 3 步:将所有控件的原点 y 的 delta 值设置为 -20,然后它会根据版本自动调整。立即使用预览,感受控件因增量值自动调整的不同。
状态栏问题修复后,展示模型视图(ZbarSDk 控制器)时的问题也会自动修复。
预览画面:
【讨论】:
如果您对此答案不满意(谁给了我反对票-1),请发表评论。这样我就可以改进我的答案。 如果我没有定义 .xib 怎么办?附言我是支持者:D(致@Ganapathy) 如果您以编程方式添加控件,如果设备版本约为 7.0,则需要将所有添加的控件(以编程方式添加)的原点 y 增加到 20.. 当我按照你的步骤进行时,我无法像你在#step2 中提到的那样设置我的查看药水 +20,因为它已被禁用。如何使可编辑? 天哪,iOS 的布局系统好乱啊。硬编码的、版本相关的偏移量?苹果是认真的吗?【参考方案2】:这个答案我迟到了,但我只想分享我所做的,基本上是最简单的解决方案
首先->转到您的info.plist File
并添加状态栏样式->透明黑色样式(Alpha of 0.5)
现在,它开始了:-
将此代码添加到您的 AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
//Whatever your code goes here
if(kDeviceiPad)
//adding status bar for IOS7 ipad
if (IS_IOS7)
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 1024, 20);
addStatusBar.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; //change this to match your navigation bar
[self.window.rootViewController.view addSubview:addStatusBar];
else
//adding status bar for IOS7 iphone
if (IS_IOS7)
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 320, 20);
addStatusBar.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; //You can give your own color pattern
[self.window.rootViewController.view addSubview:addStatusBar];
return YES;
【讨论】:
它非常简单。您可以在前 4 行中使用它。有关详细说明,我已添加屏幕短。我已经搜索了一个多小时,但没有人建议在根视图控制器中添加子视图来解决这个问题。 最好以编程方式处理框架,以防意外添加子视图。有了它。 根据您的回答:状态栏会重叠,但不会重叠主视图。它将与您添加的自定义视图重叠。我的问题是如何避免状态栏重叠。希望你理解。 使用未声明的标识符“kDeviceiPad” @Moob -"kDeviceiPad" 是 nsuserdefault,用于检查您是否使用 ipad。您可以编写自己的代码来检查 iPad。 为什么不把固定宽度改成self.window.frame.size.width,这样就不用检查设备类型了【参考方案3】:- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
[application setStatusBarStyle:UIStatusBarStyleLightContent];
[application setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
self.window.clipsToBounds =YES;
self.window.frame =CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
[self.window makeKeyAndVisible];
return YES;
将以下内容设置为 info.plist
查看基于控制器的状态栏外观 = NO;
【讨论】:
【参考方案4】:要在 ios7 中隐藏状态栏,请按照以下简单步骤操作:
在 Xcode 中转到“Resources
”文件夹并打开“(app name)-Info.plist file
”。
View controller based status bar appearance
”键并设置其值“NO
”
检查“Status bar is initially hidden
”键并设置其值“YES
”
如果密钥不存在,那么您可以通过选择顶部的“information property list
”并点击+图标来添加它
【讨论】:
【参考方案5】:MUCH MUCH MUCH 更简单的答案:
将视图的顶部与“顶部布局指南”对齐,但控制拖动“顶部布局指南”到您的视图并设置“垂直”约束。 See this answer 供图片参考。
它的工作方式是 - “顶部布局指南”会自动调整状态栏是否存在,它会全部工作 - 无需编码!
附:在这个特定的示例中,底部显示的背景也应该通过设置视图底部的适当垂直约束、到它的超级视图或其他任何东西来解决......
【讨论】:
【参考方案6】:听说我们可以同时为所有视图执行此操作
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
// Notification for the orientaiton change
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidChangeStatusBarOrientation:)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
// Window framing changes condition for iOS7 or greater
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
statusBarBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, -20, self.window.frame.size.width, 20)];//statusBarBackgroundView is normal uiview
statusBarBackgroundView.backgroundColor = [UIColor colorWithWhite:0.000 alpha:0.730];
[self.window addSubview:statusBarBackgroundView];
self.window.bounds = CGRectMake(0, -20, self.window.frame.size.width, self.window.frame.size.height);
// Window framing changes condition for iOS7 or greater
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
当我们使用方向时,我们可以在应用程序委托中添加以下方法以通过方向设置它。
- (void)applicationDidChangeStatusBarOrientation:(NSNotification *)notification
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
statusBarBackgroundView.hidden = YES;
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
int width = [[UIScreen mainScreen] bounds].size.width;
int height = [[UIScreen mainScreen] bounds].size.height;
switch (orientation)
case UIInterfaceOrientationLandscapeLeft:
self.window.bounds = CGRectMake(-20,0,width,height);
statusBarBackgroundView.frame = CGRectMake(-20, 0, 20, height);
break;
case UIInterfaceOrientationLandscapeRight:
self.window.bounds = CGRectMake(20,0,width,height);
statusBarBackgroundView.frame = CGRectMake(320, 0, 20, height);
break;
case UIInterfaceOrientationPortraitUpsideDown:
statusBarBackgroundView.frame = CGRectMake(0, 568, width, 20);
self.window.bounds = CGRectMake(0, 20, width, height);
break;
default:
statusBarBackgroundView.frame = CGRectMake(0, -20, width, 20);
self.window.bounds = CGRectMake(0, -20, width, height);
break;
statusBarBackgroundView.hidden = NO;
你应该为它添加下面的导航控制器类别
.h
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface UINavigationController (iOS6fix)
@end
.m
#import "UINavigationController+iOS6fix.h"
@implementation UINavigationController (iOS6fix)
-(BOOL)shouldAutorotate
return [[self.viewControllers lastObject] shouldAutorotate];
-(NSUInteger)supportedInterfaceOrientations
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
@end
【讨论】:
【参考方案7】:使用 Salesforce SDK 2.1 (Cordova 2.3.0),我们必须执行以下操作才能使状态栏出现在应用程序的初始加载并从后台返回(iPhone 和 iPad):
与此处发布的其他解决方案相反,这个解决方案似乎可以在设备旋转时幸存下来。
1-创建SFHybridViewController
的类别
#import "SFHybridViewController+Amalto.h"
@implementation SFHybridViewController (Amalto)
- (void)viewWillAppear:(BOOL)animated
//Lower screen 20px on ios 7
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
CGRect viewBounds = self.view.bounds;
viewBounds.origin.y = 20;
viewBounds.size.height = viewBounds.size.height - 20;
self.webView.frame = viewBounds;
[super viewWillAppear:animated];
- (void)viewDidLoad
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
CGRect viewBounds = self.view.bounds;
viewBounds.origin.y = 20;
viewBounds.size.height = viewBounds.size.height - 20;
self.webView.frame = viewBounds;
[super viewDidLoad];
@end
2-添加到AppDelegate.m
导入
#import "SFHybridViewController+Amalto.h"
3-在didFinishLaunchingWithOptions
of AppDelegate
的方法末尾注入
//Make the status bar appear
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
[application setStatusBarStyle:UIStatusBarStyleLightContent];
[application setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
4-添加到App-Info.plist
属性
View controller-based status bar appearance
的值为 NO
【讨论】:
【参考方案8】:我用下面的代码解决了这个问题
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
if(landScape mode)
if ([UIDevice currentDevice].systemVersion.floatValue>=7)
CGRect frame = self.window.frame;
frame.size.width -= 20.0f;
frame.origin.x+= 20.0f;
self.window.frame = frame;
if(portrait)
if ([[[UIDevice currentDevice]systemVersion]floatValue] >= 7.0)
[application setStatusBarStyle:UIStatusBarStyleLightContent];
CGRect frame = self.window.frame;
frame.origin.y += 20.0f;
frame.size.height -= 20.0f;
self.window.frame = frame;
return YES;
【讨论】:
非常感谢。我应用并自定义了此代码。这对我有用。【参考方案9】:#define _kisiOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
if (_kisiOS7)
[[UINavigationBar appearance] setBarTintColor:_kColorFromHEX(@"#011C47")];
else
[[UINavigationBar appearance] setBackgroundColor:_kColorFromHEX(@"#011C47")];
[[UINavigationBar appearance] setTintColor:_kColorFromHEX(@"#011C47")];
【讨论】:
【参考方案10】:有几种不同的方法。一种方法是使用 .plist 文件
添加新键“查看基于控制器的状态栏外观”并将值设置为“NO”。 添加另一个键“状态栏最初隐藏”并将值设置为“YES”。这将隐藏整个项目的状态栏。
【讨论】:
【参考方案11】:只需在viewWillAppear
中设置以下代码。
if ([[[UIDevice currentDevice] systemVersion] floatValue]<= 7)
self.edgesForExtendedLayout = UIRectEdgeNone;
【讨论】:
为啥ios中的状态栏和导航栏背景颜色不同
】为啥ios中的状态栏和导航栏背景颜色不同【英文标题】:whyStatusbarandNavigationbarbackgroundcolorsaredifferentinios为什么ios中的状态栏和导航栏背景颜色不同【发布时间】:2014-08-1414:54:06【问题描述】:我想更改状态栏的背景颜色,并... 查看详情
在 iOS 7 中,状态栏和导航栏出现在我的视图边界上
...220:06:41【问题描述】:我最近下载了Xcode5DP来测试我在iOS7中的应用程序。我注意到并确认的第一件事是,我的视图边界并不总是根据状态栏和导航栏调整大小。在viewDidLayoutSubviews中,我打印视图的边界 查看详情
ios下状态栏和导航栏的控制问题
iOS的项目多数会遇到控制状态栏和导航栏的问题,比如隐藏状态栏、控制状态栏的文字颜色等,导航栏也有同样需求。本文总结一下操作方法。首先一点,IOS的界面分为状态栏和导航栏,状态栏是指显示电池、时... 查看详情
iOS 7,状态栏和导航栏:像 Reeder 一样使用侧面板隐藏或滑动
】iOS7,状态栏和导航栏:像Reeder一样使用侧面板隐藏或滑动【英文标题】:iOS7,statusbarandnavigationbar:hidingorslidingwithsidepanelsasReederdoes【发布时间】:2014-12-2208:13:09【问题描述】:我想这是一个旧的。我有一个带有菜单的滑动面板(J... 查看详情
ios导航栏和状态栏
...ewController的页面布局会限制在这些Bar之间。IOS的界面分为状态栏和导航栏,状态栏是指显示电池、时间的最顶部的一个窄条,高度为20个点;而导航栏是紧接着状态栏的44个点高度的横条,一般用于显示app标题,返回按钮等操作... 查看详情
Xcode 13 - swift OS 15 中的导航栏和状态栏文本颜色变化
】Xcode13-swiftOS15中的导航栏和状态栏文本颜色变化【英文标题】:Xcode13-NavigationbarandstatusbartextcolorchanginginswiftOS15【发布时间】:2022-01-1010:15:10【问题描述】:最近我将我的Xcode更新为13,之后,我遇到了导航栏和状态栏的一些问... 查看详情
iOS 7 中 UIActivityViewControllers 的模态状态栏和导航栏文本颜色
】iOS7中UIActivityViewControllers的模态状态栏和导航栏文本颜色【英文标题】:ModalstatusbarandnavigationbartextcolorsfromUIActivityViewControllersiniOS7【发布时间】:2013-11-0516:47:36【问题描述】:当我使用UIActivityViewController时,在用户选择一个活... 查看详情
iOS 7 半透明标签栏和导航栏
...只要设置UITabBar为了半透明,我在应用程序的四个选项卡中的一个中出现了一种奇怪的效果。让我用一些图像来解释:此图 查看详情
如何匹配导航栏与状态栏ios7
】如何匹配导航栏与状态栏ios7【英文标题】:HowtomatchNavigationbarwithstatusbarios7【发布时间】:2014-02-0704:38:37【问题描述】:我正在开发一个基于UINavigationController的应用程序,其中我呈现的视图之一是模态的,我需要一个手动添加... 查看详情
标签栏和导航控制器应用程序中的状态恢复
】标签栏和导航控制器应用程序中的状态恢复【英文标题】:StateRestorationinTabBarandNavigationControllerApp【发布时间】:2015-09-0905:26:31【问题描述】:目标:我正在尝试恢复基于标签控制器的应用的状态(每个标签上都有导航控制器... 查看详情
隐藏状态栏和导航栏位置
】隐藏状态栏和导航栏位置【英文标题】:Hidingstatusbarandnavigationbarposition【发布时间】:2014-05-2618:30:26【问题描述】:我有一个无法处理的问题。我有两个视图控制器,我使用[[UIApplicationsharedApplication]setStatusBarHidden:isHiddenwithAnima... 查看详情
iOS 8 -- 对导航栏和状态栏应用模糊
】iOS8--对导航栏和状态栏应用模糊【英文标题】:iOS8--ApplyblurtonavigationbarANDstatusbar【发布时间】:2015-02-0423:01:32【问题描述】:我正在尝试向导航栏和状态栏添加模糊效果。我的问题是导航栏上的模糊效果很好,但状态栏没有模... 查看详情
iOS 状态栏和导航栏颜色相同
】iOS状态栏和导航栏颜色相同【英文标题】:SamecolorforStatusBarandNavigationBariOS【发布时间】:2017-03-2614:15:22【问题描述】:我从控件中手动添加了导航栏如何使状态栏背景颜色=与导航栏相同【问题讨论】:这应该可以帮助你***.com... 查看详情
关闭模态视图后的状态栏和导航栏问题
】关闭模态视图后的状态栏和导航栏问题【英文标题】:statusbarandNavigationbarproblemafterdismissedmodalview【发布时间】:2011-04-1423:46:57【问题描述】:当按下“联系我们”按钮时,应用程序会启动mailcomposer模式视图(MFMailComposeViewControll... 查看详情
iOS:状态栏和导航栏:空格或底层
】iOS:状态栏和导航栏:空格或底层【英文标题】:iOS:StatusbarandNavigationbar:SpaceorUnderlaying【发布时间】:2013-08-0513:26:57【问题描述】:如何以规范的方式操作状态栏和导航?所以,我的目标是同时隐藏和显示状态栏和导航栏。我... 查看详情
在状态栏和导航栏之间添加图片
】在状态栏和导航栏之间添加图片【英文标题】:Addimagebetweenstatusbarandnavigationbar【发布时间】:2014-03-2904:19:56【问题描述】:我正在尝试在IOS的状态栏和导航栏之间添加图像。这可能吗?您能指导我如何实现这一目标吗?基本... 查看详情
在 iPhone X 上没有导航栏和状态栏的标签顶部距离问题
】在iPhoneX上没有导航栏和状态栏的标签顶部距离问题【英文标题】:LabeltopdistanceissuewithoutnavigationbarandStatusBarwithiPhoneX【发布时间】:2018-09-2504:17:55【问题描述】:我有一个视图控制器,由于UI要求,我需要在其中隐藏状态栏和... 查看详情
在 iPhone X 上,分别控制显示/隐藏导航栏和状态栏
...分别控制显示和隐藏NavigationBar和StatusBar或我的应用程序中的每个屏幕。在iPhone6、iPhone7和iPhone8上,没问题。但在iPhoneX上,当显示N 查看详情