繁体   English   中英

在iPhone底部添加StatusBar

[英]Adding StatusBar at the bottom of iPhone

我想在iPhone的底部显示一个状态栏,就像显示Gmail帐户中的状态栏一样,表明它正在检查邮件。 我在此线程中尝试了以下解决方案在iPhone中的StatusBar上添加视图

但是状态栏没有出现,然后我使用了相同的代码,没有做任何修改就将其显示在默认状态栏的顶部,并且它也没有出现。

我还尝试了使用MTStatusBarOverlay的另一种解决方案,当我尝试将其框架更改为底部时,在屏幕中间出现了一个黑色矩形

有什么帮助吗?

这是代码

// new class i have created
@interface BottomStatusBarOverlay :  UIWindow

@end

@implementation BottomStatusBarOverlay
- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        // Place the window on the correct level and position
        self.windowLevel = UIWindowLevelStatusBar+1.0f;
        self.frame = [[UIApplication sharedApplication] statusBarFrame];
        self.alpha = 1;
        self.hidden = NO;
        // 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:@"statusBarBackgroundGrey.png"] stretchableImageWithLeftCapWidth:2.0f topCapHeight:0.0f];
        [self addSubview:backgroundImageView];
    }
    return self;
}
@end

// usage in my view controller in a button action
@implementation MainViewController
-(IBAction)showBottomStatusbar:(id)sender {
    BottomStatusBarOverlay *bottomStatusBarOverlay = [[BottomStatusBarOverlay alloc] init];
    bottomStatusBarOverlay.hidden = NO;
}

您发布的代码显示showBottomStatusbar方法创建了一个BottomStatusBarOverlay实例,但是您实际上从未将其作为任何子视图添加。

我没有在iPhone上使用Gmail应用程序。 因此,我不确定它的外观或功能。 但是,我过去创建的通知栏似乎与您描述的类似。 它会动画显示在屏幕底部,显示一条消息三秒钟,然后向后滑动。 我通过将条形图添加到应用程序的窗口来完成此操作,这将确保它覆盖应用程序当前显示的任何视图。 但是,如果您的应用程序中不需要全局栏,则可以将栏添加到当前处于活动状态的任何视图中。 这是获取应用程序窗口参考的方法:

UIApplication* app = [UIApplication sharedApplication];
UIWindow* appWin = app.delegate.window;

要设置动画,可以使用animateWithDuration,如下所示:

[UIView animateWithDuration:0.3 
                 animations:^ { 
                     // However you want to animate on to the screen.
                     // This will slide it up from the bottom, assuming the
                     // view's start position was below the screen.
                     view.frame = CGRectMake(0, 
                                             winHeight - viewHeight, 
                                             winWidth, 
                                             viewHeight);
                 }
                 completion:^(BOOL finished) {
                     // Schedule a timer to call a dismiss method after
                     // a set period of time, which would probably perform
                     // an animation off the screen.
                     dismissTimer = [NSTimer 
                                     scheduledTimerWithTimeInterval:3
                                     target:globalMessage
                                     selector:@selector(dismiss)
                                     userInfo:nil
                                     repeats:NO];
                 }];

希望这可以帮助。

暂无
暂无

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

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