【问题标题】:Status bar overlapping when using ECSlidingViewController使用 ECSlidingViewController 时状态栏重叠
【发布时间】:2013-11-27 06:57:56
【问题描述】:

我在AppDelegate实现器函数didFinishLaunchingWithOptions中添加了如下代码

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);
    [[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 有关?

【问题讨论】:

标签: ios ios7 ecslidingviewcontroller


【解决方案1】:

尝试此代码并在 Info.plist 中设置此查看基于控制器的状态栏外观 = 否

- (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];
        }
    }
}

【讨论】:

    【解决方案2】:

    为了在您使用导航控制器时使用 EECCSlidingViewController 支持 ios7,请取消选中从视图控制器 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];
    }
    

    并在视图中完成启动添加以下内容

    [application setStatusbarStyle:UIStatusBarStyleTranslucent];
    

    在 plist 文件中添加 ViewControllerBasedStatuschangedAppearence 为 NO

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-20
      • 2013-02-04
      相关资源
      最近更新 更多