繁体   English   中英

ios5.1在iphone状态栏上添加了一个UIView

[英]ios5.1 adding a UIView on top of iphone statusbar

我想在状态栏上添加一个视图。 我一直关注这个帖子: 在iPhone中添加StatusBar视图

出于某种原因,当我创建窗口并将Hidden设置为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;
}

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

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

但是,视图仍然没有显示出来。 知道为什么?

屏幕截图显示使用私有api的错误

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

self.window.windowLevel = UIWindowLevelStatusBar;

然后在任何地方将自己的视图添加到应用程序窗口

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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM