2013-11-27 72 views
1

當重疊添加以下代碼中的AppDelegate實現者功能didFinishLaunchingWithOptions狀態欄使用ECSlidingViewController

如果([[[的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); 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(applicationDidChangeStatusBarOrientation:) 
               name:UIApplicationDidChangeStatusBarOrientationNotification 
               object:nil]; 

}

以及這個函數被調用:

- (void)applicationDidChangeStatusBarOrientation:(NSNotification *)notification 
{ 
    int a = [[notification.userInfo objectForKey: UIApplicationStatusBarOrientationUserInfoKey] intValue]; 
    int w = [[UIScreen mainScreen] bounds].size.width; 
    int h = [[UIScreen mainScreen] bounds].size.height; 

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 
    UIDeviceOrientation orientationa = [[UIDevice currentDevice] orientation]; 

    if (orientation==4) 
    { 
     self.window.frame = CGRectMake(20,0,w-20,h+20); 
    }else if(orientation==1) 
    { 
     self.window.frame = CGRectMake(0,20,w,h); 
    }else 
    { 
     self.window.frame = CGRectMake(-20,0,w+20,h+20); 
    } 
} 

這適用於獲取狀態欄即使在旋轉時也不重疊,但是當點擊一個按鈕後,它會向後端發出更改並重疊,直到它再次旋轉,任何人都知道爲什麼會發生這種情況?我懷疑這可能與ECSlidingViewController有關?

+0

http:// stackoverf low.com/questions/17074365/status-bar-and-navigation-bar-appear-over-my-views-bounds-in-ios-7 – the1pawan

+0

請參閱http://stackoverflow.com/a/20093515/1545180以及這http://stackoverflow.com/a/19025547/1545180 – Ganapathy

回答

1

試試這個代碼&集這Info.plist中查看基於控制器的狀態欄外觀= NO

- (void) viewDidLoad 
{ 
    [super viewDidLoad]; 

    float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue]; 

    if (systemVersion >= 7.0f) 
    { 
     CGRect tempRect; 

     for (UIView *sub in [[self view] subviews]) 
     { 
      tempRect = [sub frame]; 

      tempRect.origin.y += 20.0f; //Height of status bar 

      [sub setFrame:tempRect]; 
     } 
    } 
} 
0

無論何時你使用導航控制器,爲了支持ios7和ECECSlidingViewController,取消所有的選項以從View控制器XIB擴展邊緣,並且你沒有使用導航控制器,你可以在Viewcontroller.m文件中使用下面的代碼。

-(void)viewDidLayoutSubviews 
{ 
    if([[[UIdevice currentdevice]systemversion]floatvalue] >=7.0f){ 
    CGRect screen = [UIScreen mainscreen]bounds]; 
    CGRect frame = self.view.frame; 
    frame.origin.y = 20.0f; 
    frame.size.height = screen.size.height - 20; 
} 
    [self.view layoutsubviews]; 
} 

,並鑑於didfinishlaunching添加以下

[application setStatusbarStyle:UIStatusBarStyleTranslucent]; 

和plist文件添加到ViewControllerBasedStatuschangedAppearence NO