gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 19:41:34 24 4
gpt4 key购买 nike

我正在尝试在状态栏顶部添加一个 View 。我一直在关注这个帖子:Adding view on StatusBar in iPhone

由于某种原因,当我创建窗口并将“隐藏”设置为“否”时,该 View 似乎没有显示在状态栏顶部。这个实现在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;
}

在我的 View Controller 中,我创建了新窗口并在 viewDidLoad 中调用它:

StatusBarOverlay *overlayWindow = [[StatusBarOverlay alloc] initWithFrame:CGRectZero];
[overlayWindow makeKeyAndVisible];

但是, View 仍然没有显示。知道为什么吗?

Screenshot showing error using private api

最佳答案

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

self.window.windowLevel = UIWindowLevelStatusBar;

然后将您自己的 View 添加到应用程序窗口的任意位置:

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

这个问题最近出现在我身上,我就是通过这种方式解决的

关于iphone - ios5.1 在iphone状态栏顶部添加UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11031094/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com