像iOS 6一样的iOS 7状态栏

我有一个支持景观和肖像模式的应用程序。 我需要像iOS 6一样的行为状态栏。最简单的方法是什么?

我已经尝试了堆栈溢出问题的iOS 7状态栏回到iOS 6风格的解决scheme ,但它不起作用。 我的子视图取决于视图大小,我的观点不能正确拉伸。 我不想更新我的XIB文件; 我只是想添加一些帮助我的东西。 我不知道这可能是什么(黑客或祈祷)。

你可以尝试在你的ViewWillapar或DidAppear中写这个。 这里我们将视图框架向下移动20个像素。

CGRect frame = self.view.frame; frame.origin.y = 20; if (self.view.frame.size.height == 1024 || self.view.frame.size.height == 768) { frame.size.height -= 20; } self.view.frame = frame; 

这将工作,但是这不是一个好主意。 如果有帮助,您也可以通过调用以下方法,根据您的应用背景将状态栏的文本颜色更改为明亮或黑暗。

 -(UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; // For light status bar return UIStatusBarStyleDefault // For Dark status bar } 

如果你使用的是Xcode 5,而你正在iOS 7中安装,那么很抱歉,这不会发生(据我所知)。

如果你想看到像iOS 6的iOS 7的状态栏,而不是在Xcode 4.xx中打开你的项目,并在iOS 7中安装。我发现这种方法的一个问题是,有时Xcode 4.xx不能识别iOS 7设备。

但是,如果你的Xcode 4.xx可以显示你的iOS 7设备,那么它将工作。

从Xcode 4.xx生成的.api可以在iOS 6和iOS 7上运行,但是在iOS 7上不会有额外的空间(状态栏)和键盘,select器,开关等的新外观。但是, ,你会得到新的UIAlertView(我不知道为什么这是新的,其他控件是旧的。)

我希望我们很快能够在Xcode 5中获得更好的解决scheme。

更新:

我find了从Xcode 5作为Xcode 4运行应用程序的方法。这只是基础SDK的问题。 如果您想从Xcode 5构build为Xcode 4(iOS 6 SDK),请执行以下操作。

  1. closuresXcode 4和5。

  2. 在Xcode 4中去

    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs

  3. 在这里你会findiPhoneOS6.1.sdk 。 复制这个文件夹。 现在进入Xcode 5的同一条path。 在Xcode 5中,你会发现iPhoneOS7.0.sdk 。 粘贴iPhoneOS6.1.sdk

  4. 现在closuresFinder并启动Xcode 5.转到project target setting -> Build Setting并findBase SDK。 selectiOS 6.1作为基本SDK。 这也适用于6.0。 你只需要findiPhoneOS6.0.sdk

  5. 现在,您将在运行下拉框中看到设备名称两次。 一个用于SDK 7.0,一个用于SDK 6.1。 所以,现在你可以用iOS 6 SDK和iOS 7 SDK运行两种方式。

我希望这会帮助别人。

我最近不得不解决一个类似的问题,然后以一种稍微不同的方式来解决这个问题。

这个方法是使用一个额外的视图控制器,作为原来是我的rootViewController的容器视图控制器。 首先,我设置了一个这样的容器:

 _containerView = [[UIView alloc] initWithFrame:[self containerFrame]]; _containerView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; _containerView.clipsToBounds = YES; [self.view addSubview:_containerView]; [self.view setBackgroundColor:[UIColor blackColor]]; [UIApplication.sharedApplication setStatusBarStyle:UIStatusBarStyleLightContent animated:NO]; 

containerFrame是这样定义的:

 - (CGRect)containerFrame { if ([MyUtilityClass isSevenOrHigher]) { CGFloat statusBarHeight = [MyUtility statusBarHeight]; //20.0f return CGRectMake(0, statusBarHeight, self.view.bounds.size.width, self.view.bounds.size.height - statusBarHeight); } return self.view.bounds; } 

最后,我添加了最初的我的rootViewController作为新的一个childViewController:

 //Add the ChildViewController self.childController.view.frame = self.containerView.bounds; self.childController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; [self addChildViewController:self.childController]; [self.containerView addSubview:self.childController.view]; [self.childController didMoveToParentViewController:self]; 

注意事项: – Modal视图控制器仍然会以iOS7风格呈现,所以我仍然需要以某种方式来解释。

希望这可以帮助别人!

本指南帮助我。

http://www.doubleencore.com/2013/09/developers-guide-to-the-ios-7-status-bar/

自动布局是处理20点尺寸差异最可靠的方法。

如果您没有使用自动布局,Interface Builder为您提供了处理iOS 7和旧版本之间的屏幕大小差异的工具。 closures“自动布局”时,您会注意到界面生成器实用工具区(右侧窗格)的大小选项卡中有一个区域,允许您设置iOS 6/7三angular洲。

1)这是一个黑客,但它的工作原理!

如果您不使用UIAlertView或KGStatusBar,请使用它!

 #import <objc/runtime.h> @interface UIScreen (I_love_ios_7) - (CGRect)bounds2; - (CGRect)boundsForOrientation:(UIInterfaceOrientation)orientation; @end @implementation UIScreen (I_love_ios_7) - (CGRect)bounds2 { return [self boundsForOrientation:[[UIApplication sharedApplication] statusBarOrientation]]; } - (CGRect)boundsForOrientation:(UIInterfaceOrientation)orientation { CGRect resultFrame = [self bounds2]; if(UIInterfaceOrientationIsLandscape(orientation)) resultFrame.size.width -= 20; else resultFrame.size.height -= 20; return resultFrame; } @end void Swizzle(Class c, SEL orig, SEL new) { Method origMethod = class_getInstanceMethod(c, orig); Method newMethod = class_getInstanceMethod(c, new); if(class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) class_replaceMethod(c, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod)); else method_exchangeImplementations(origMethod, newMethod); } @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { Swizzle([UIScreen class], @selector(bounds2), @selector(bounds)); [application setStatusBarStyle:UIStatusBarStyleLightContent]; self.window.clipsToBounds =YES; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidChangeStatusBarOrientation:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil]; NSDictionary* userInfo = @{UIApplicationStatusBarOrientationUserInfoKey : @([[UIApplication sharedApplication] statusBarOrientation])}; [[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationWillChangeStatusBarOrientationNotification object:nil userInfo:userInfo]; } return YES; } - (void)applicationDidChangeStatusBarOrientation:(NSNotification *)notification { UIInterfaceOrientation orientation = [[notification.userInfo objectForKey: UIApplicationStatusBarOrientationUserInfoKey] intValue]; CGSize size = [[UIScreen mainScreen] boundsForOrientation:orientation].size; int w = size.width; int h = size.height; float statusHeight = 20.0; switch(orientation){ case UIInterfaceOrientationPortrait: self.window.frame = CGRectMake(0,statusHeight,w,h); break; case UIInterfaceOrientationPortraitUpsideDown: self.window.frame = CGRectMake(0,0,w,h); break; case UIInterfaceOrientationLandscapeLeft: self.window.frame = CGRectMake(statusHeight,0,w,h); break; case UIInterfaceOrientationLandscapeRight: self.window.frame = CGRectMake(0,0,w,h); break; } } @end 

2)创build类别,并始终使用contentView而不是view

 @interface UIViewController(iOS7_Fix) @property (nonatomic, readonly) UIView* contentView; - (void)updateViewIfIOS_7; @end @implementation UIViewController(iOS7_Fix) static char defaultHashKey; - (UIView *)contentView { return objc_getAssociatedObject(self, &defaultHashKey)?: self.view; } - (void)setContentView:(UIView *)val { objc_setAssociatedObject(self, &defaultHashKey, val, OBJC_ASSOCIATION_RETAIN_NONATOMIC) ; } - (void)updateViewIfIOS_7 { if([[[UIDevice currentDevice] systemVersion] floatValue] < 7 || objc_getAssociatedObject(self, &defaultHashKey)) return; UIView* exchangeView = [[UIView alloc] initWithFrame:self.view.bounds]; exchangeView.autoresizingMask = self.view.autoresizingMask; exchangeView.backgroundColor = [UIColor blackColor]; UIView* view = self.view; if(self.view.superview){ [view.superview addSubview:exchangeView]; [view removeFromSuperview]; } [exchangeView addSubview:view]; self.view = exchangeView; CGRect frame = self.view.bounds; frame.origin.y += 20.0; frame.size.height -= 20.0; view.frame = frame; view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; [self setContentView:view]; } 

在每个UIViewController

 - (void)viewDidLoad { [super viewDidLoad]; [self updateViewIfIOS_7]; UILabel* lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 130, 30)]; lab.backgroundColor = [UIColor yellowColor]; [self.contentView addSubview:lab]; //... } 

肖像景观