隐藏iPhone状态栏可将我的tableViews拉高20px

时间:2010-05-30 03:13:04

标签: iphone uiviewcontroller uiapplicationdelegate

在执行异步HTTP请求时,我会隐藏iPhone状态栏并在我自己的自定义UIViewController中设置动画以显示上传状态。因此,用户不会看到信号强度,载波,时间和电池寿命,而是根据HTTP请求的进度获取消息。我的状态栏高度为20px,非常适合状态栏。完成HTTP活动后,自定义视图将动画化,iPhone状态栏将重新设置为动画。

我想完全避免隐藏iPhone状态栏,而是将我的自定义视图置于状态栏的顶部。目前,如果我调用自定义视图动画并将iPhone状态栏设置为可见,则我的自定义视图就在后面。

这是我的代码:

-(void) animateStatusBarIn {
        CGRect statusFrame = CGRectMake(0.0f, -20.0f, 320.0f, 20.0f);
        UploadStatusBar *statusView = [[UploadStatusBar alloc] initWithNibName:@"UploadStatusBar" bundle:nil];
    self.status = statusView;
    [statusView release];
    status.view.frame = statusFrame;
    [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
    [window addSubview:status.view];
    [UIView beginAnimations:@"slideDown" context:nil];
    [UIView setAnimationDuration:0.3];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationFinished:)];
    status.view.frame = CGRectMake(0.0f, 0.0f, 320.0f, 20.0f);
    [UIView commitAnimations];

}   

-(void) animateStatusBarOut {
    [UIView beginAnimations:@"slideUp" context:nil];
    [UIView setAnimationDuration:0.3];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationFinished:)];
    status.view.frame = CGRectMake(0.0f, -20.0f, 320.0f, 20.0f);
    [UIView commitAnimations];
}

-(void)animationFinished:(NSString *)name {
    if ([name isEqualToString:@"slideDown"]) {

    }
    if ([name isEqualToString:@"slideUp"]) {
            [[UIApplication sharedApplication]setStatusBarHidden:NO animated:YES];
        [status.view removeFromSuperview];
    }


}

没有[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES] 你看不到我的自定义视图。如何让我的自定义视图显示在状态栏的顶部,这样我就不必隐藏它了?

谢谢!

2 个答案:

答案 0 :(得分:2)

使您的特殊视图成为自己的UIWindow。将UIWindow的windowLevel设置为UIWindowLevelStatusBar。如果它仍然不在顶部,你可以在UIWindow上使用bringSubviewToFront:(记住,UIWindow是一个UIView)将它带到该级别的顶部。

答案 1 :(得分:0)

在这里回答:

Add UIView Above All Other Views, Including StatusBar

必须创建UIWindow并将其windowLevel属性设置为statusBarLevel。