`
810364804
  • 浏览: 781789 次
文章分类
社区版块
存档分类
最新评论

(iPhone/iPad开发)适配Xcode 5+iOS 7之statusBar

 
阅读更多

众所周知,iOS7在statusBar问题上和之前低版本系统不一样,在适配iOS 7时,statusBar也是需要适配的一部分,我这边的处理方法是

首先,需要在Info.plist配置文件中,增加一下一个键值对。
View controller-based status bar appearance = NO

然后再相应的ViewController里单独处理,这是为了避免有些不必要的Controller反受影响

- (void)viewDidLoad:(BOOL)animated
{
    [super viewDidLoad:NO];
    CGRect frame = self.view.frame;
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        frame.origin.y = 20;
        frame.size.height = self.view.frame.size.height - 20;
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    } else {
        frame.origin.y = 0;
    }
    self.view.frame = frame;
}

然后,在接下来的addSubView时,最好使用相对布局,设置距离statusBar最近的View frame时,origin.y,最好设置成self.view.frame.origin.y,而不是单独是不是判断iOS7再设置0或者20,如此,基本上statusBar相关问题就已经适配结束。



备注:还有一种思路,在

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions

中,从window层面设置frame.待尝试。

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {

[application setStatusBarStyle:UIStatusBarStyleLightContent];

self.window.clipsToBounds =YES;

self.window.frame = CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);

//added on 19th Sep
self.window.bounds = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height);
}



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics