ios - 使用 ECSlidingViewController 时状态栏重叠

标签 ios ios7 ecslidingviewcontroller

我在 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 有关?

最佳答案

尝试这段代码并在 Info.plist View controller-based status bar appearance = 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];
        }
    }
}

关于ios - 使用 ECSlidingViewController 时状态栏重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20235860/

相关文章:

iOS bbc iPlayer 风格滚轮

android - Android 可以接收 IOS 蓝牙信号吗

ios - 在 Swift 中更改类型

ios - 如何在 iOS 7 的导航栏上获得模糊和半透明的效果?

ios - 我可以从左到右有两个 ECSlidingViewController Drawer 吗?

ios - 我如何在 iOS 中为 ECSlidingViewController 构建 3D 转换?

iphone - viewWillAppear 时 ECSlidingViewController 错误(对象不能为 nil)

ios - 为什么在Swift中调用popoverPresentationController会出现状态栏?

CALayer 上的 IoS 7 核心文本模糊

ios - 我可以在 iOS 7 上运行的应用程序中使用 swift sdk 吗?