我正在尝试在状态栏顶部添加一个视图。我一直在关注这个 SO 帖子:在 iPhone 中的 StatusBar 上添加视图
出于某种原因,当我创建窗口并将隐藏设置为 NO 时,视图似乎不会显示在状态栏的顶部。这个实现在 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;
}
在我的视图控制器中,我创建了新窗口并在 viewDidLoad 中调用它:
StatusBarOverlay *overlayWindow = [[StatusBarOverlay alloc] initWithFrame:CGRectZero];
[overlayWindow makeKeyAndVisible];
但是,视图仍然没有显示。知道为什么吗?