개발

iOS 7 Status Bar 문제 해결하기

지승준 2014. 1. 24. 10:52

iOS 6 기반으로 만든 앱을 iOS 7 SDK로 컴파일하면 너무 많은 문제들이 도출된다. 그 중에 가장 눈에 띄는 게 바로 Status Bar가 아닐까 생각한다. 기존과 다르게 iOS 7부터는 무려 20pt 자리를 차지하지 않는다. 그렇기 때문에 당연히 이를 고려하지 않았던 iOS 6 기반앱들은 졸지에 모든 view가 Status bar 자리까지 차지하는 문제가 발생한다. 이 문제를 깔끔하게 해결할 수 있는 방법은 그리 많지 않은 것 같다. 조금 번잡하더라도 다음과 같은 절차로 처리하면 기존앱의 Status bar를 그대로 유지하면서 view도 원래의 위치에 보일 수 있도록 할 수 있다.


1. info.plist에 UIViewControllerBasedStatusBarAppearance를 NO로 설정한다. 

2. AppDelegate의 application:didFinishLaunchingWithOptions:가 호출될때 다음코드를 추가한다. 

1
2
3
4
5
6
7
8
9
10
11
12
if ([[UIDevice currentDevice].systemVersion floatValue] < 7) {
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
else {
    // handling statusBar (iOS7)
    application.statusBarStyle = UIStatusBarStyleLightContent;
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
    self.window.clipsToBounds = YES;
 
    // handling screen rotations for statusBar (iOS7)
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidChangeStatusBarOrientationNotification:) 
    name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
}
cs


3. 다음 메소드를 추가한다. 

1
2
3
4
- (void)applicationDidChangeStatusBarOrientationNotification:(NSNotification *)notification {
    // handling statusBar (iOS7)
    self.window.frame = [UIScreen mainScreen].applicationFrame;
}
cs


위 3단계는 결국 앱에서 생성할 window객체의 frame자체를 설정하는 형태이다. iOS 6기반으로 만든 앱을 큰 코드 변경없이 window의 frame만 조절하는 것이기 때문에 유용하다. 새로 iOS 7 앱을 만든다면 이 코드는 사용하지 말자.