隐藏在状态栏iOS后面的通知栏

时间:2015-02-27 07:42:17

标签: ios objective-c

我试图在我的应用中添加通知消息。对于具有标签栏的视图(我怀疑),通知消息部分隐藏在状态栏下。进入没有标签栏的视图后,我会在状态栏下看到完整的通知消息。此后,在应用程序的所有视图中,通知消息都会完美显示。 用于显示通知消息的代码是:

UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window)
    window = [[UIApplication sharedApplication].windows lastObject];
windowLevel = [[[[UIApplication sharedApplication] delegate] window] windowLevel];
[[[[UIApplication sharedApplication] delegate] window] setWindowLevel:UIWindowLevelStatusBar+1];
CGRect presentationFrame = self.frame;
CGRect viewBounds = [[[window subviews] lastObject] bounds];
self.frame = CGRectMake(0, 0, viewBounds.size.width, -64);
[[[window subviews] lastObject] addSubview:self];

if (self.animationType == MPGNotificationAnimationTypeLinear) {
    [UIView animateWithDuration:0.25
                     animations:^{
                         self.frame = presentationFrame;
                     }];
}

我在AppDelegate中使用以下代码来创建状态栏:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
    self.window.clipsToBounds = YES;
    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleLightContent];

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
    {
        self.window.frame =  CGRectMake(20, 0,self.window.frame.size.width-20,self.window.frame.size.height);
        self.window.bounds = CGRectMake(20, 0, self.window.frame.size.width, self.window.frame.size.height);
    } else
    {
        self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
        self.window.bounds = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height);
    }
}

0 个答案:

没有答案