如何使用视图或窗口覆盖状态栏?

时间:2013-08-24 19:46:27

标签: ios ios6 rotation uiwindow

上一个标题:在状态栏上旋转自定义UIWindow导致在使用iOS 6旋转期间显示黑条

我创建了一个自定义UIWindow,我将其放在状态栏上,并带有透明背景色。

旋转时,会出现黑条,我不知道原因:

enter image description here enter image description here

这只发生在 iOS 6 上,而 iOS 5 的设备不会显示黑条。

AppDelegate 中,我创建了一个 UIWindow

@property (strong, nonatomic) GRWStatusBarOverlayWindow *statusBarWindow;

CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
self.statusBarWindow = [[GRWStatusBarOverlayWindow alloc] initWithFrame:statusBarFrame];
self.statusBarWindow.hidden = NO;

我将状态栏窗口的 rootViewController 设置为虚拟 UIViewController

@interface GRWStatusBarRootViewController : UIViewController

@interface      GRWStatusBarOverlayWindow : UIWindow
@implementation GRWStatusBarOverlayWindow

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.rootViewController = [[GRWStatusBarRootViewController alloc] initWithNibName:nil bundle:nil];

        self.windowLevel = UIWindowLevelStatusBar + 1.0f;
        self.frame = frame;

        self.statusBarView = [[UIView alloc] initWithFrame:frame];
        self.statusBarView.backgroundColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.25];
        [self addSubview:self.statusBarView];
    }
    return self;
}

无论有没有Nib,还有其他方法,我都尝试过,但没有取得圆满成功。

我得到的最接近的是如果我离开 rootViewController nil ,然后我确实得到没有黑条的旋转,但是我收到了一条消息:

Application windows are expected to have a root view controller at the end of application launch

我总是喜欢干净的构建和执行,没有任何错误或警告,所以我想找到一个解决方案,删除该消息和黑条。但是,如果这个消息是无害的,我会接受它,尽管那时我不得不想知道其他问题可能会在未来发生。

有没有人对此问题有任何见解?任何指导或指示都将不胜感激。

0 个答案:

没有答案