ios5.1在iphone状态栏顶部添加UIView

ios5.1在iphone状态栏顶部添加UIView,iphone,ios5,uikit,Iphone,Ios5,Uikit,我正在尝试在状态栏顶部添加一个视图。我一直在关注这篇文章: 由于某些原因,当我创建窗口并将“隐藏”设置为“否”时,视图不会显示在状态栏的顶部。这个实现在ios5.1中仍然有效吗 谢谢 这是我的自定义UIWindow类: @implementation StatusBarOverlay - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Place the windo

我正在尝试在状态栏顶部添加一个视图。我一直在关注这篇文章:

由于某些原因,当我创建窗口并将“隐藏”设置为“否”时,视图不会显示在状态栏的顶部。这个实现在ios5.1中仍然有效吗

谢谢

这是我的自定义UIWindow类:

@implementation StatusBarOverlay

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
    // Place the window on the correct level and position
    self.hidden = NO;
    self.windowLevel = UIWindowLevelStatusBar+1.0f;
    self.frame = [[UIApplication sharedApplication] statusBarFrame];

    // Create an image view with an image to make it look like a status bar.
    UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:self.frame];
    backgroundImageView.image = [UIImage imageNamed:@"bar_0.png"];
    backgroundImageView.animationImages = [NSArray arrayWithObjects:[UIImage     imageNamed:@"bar_1.png"],
                                           [UIImage imageNamed:@"bar_2.png"],
                                           [UIImage imageNamed:@"bar_3.png"],
                                           nil];
    backgroundImageView.animationDuration = 0.8;
    [backgroundImageView startAnimating];
    [self addSubview:backgroundImageView];
}
return self;
}
在我的viewcontroller中,我创建了新窗口,并在viewDidLoad中调用此窗口:

StatusBarOverlay *overlayWindow = [[StatusBarOverlay alloc] initWithFrame:CGRectZero];
[overlayWindow makeKeyAndVisible];
但是,视图仍然没有显示。你知道为什么吗


您可以创建一个新的
ui窗口
,并将视图添加到该窗口中。将windows框架设置为
[[UIApplication sharedApplication]statusBarFrame]
并调用
makeKeyAndVisible
使其可见。

最后,我将UIWindow子类化,并将其作为应用程序AppDelegate中的主UIWindow。我添加了任何自定义视图,并将窗口级别设置为UIWindowLevelStatusBar,以显示在状态栏顶部。

将应用程序的窗口级别设置为UIWindowLevelStatusBar:

self.window.windowLevel = UIWindowLevelStatusBar;
然后将您自己的视图添加到应用程序窗口的任意位置:

[[[UIApplication sharedApplication]delegate].window addSubview:yourview];

最近我遇到了这个问题,我通过这种方式解决了它

我尝试调用makeKeyAndVisible,但仍然没有成功。我用我的代码示例更新了我的问题。谢谢你的努力!你提到的帖子顶部说,苹果商店拒绝了该应用,因为它试图这么做。有什么原因不能只隐藏状态栏,然后创建一个类似于状态栏的子视图,该子视图可以嵌入到现在有隐藏状态栏的视图中?苹果在一千年后不会允许这样做。你的应用程序被拒绝的速度比塔可钟传来的塔可通过你的肠道更快。