簡體   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