简体   繁体   中英

Adding StatusBar at the bottom of iPhone

I want to show a status bar in the bottom of the iPhone like the one in Gmail account that is appear to indicate that it is checking mail. I have tried the following solution in this thread Adding view on StatusBar in iPhone

but the status bar didn't appear, then i used the same code without any modification to show it in the top of the default status bar and it also didn't appear.

i have tried also another solution using MTStatusBarOverlay , when i tried to change its frame to be at the bottom i got a black rectangl in the middle of the screen

any help?

here is the code

// 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;
}

The code you posted shows that your showBottomStatusbar method creates a BottomStatusBarOverlay instance, but you never actually add it as a subview to anything.

I don't use the Gmail app on iPhone. So, I'm not sure what it looks like or how it functions. However, I have create a notification bar in the past that seems similar to what you described. It animates on to the bottom of the screen, shows a message for three seconds, and then slides back off. I accomplished this by adding the bar to the application's window, which will ensure it overlays any view the application is currently showing. You could, however, add the bar to any view that is currently active, if you don't need a global bar within your app. Here's how you get the app's window reference:

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

To animate, you can use animateWithDuration, like so:

[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];
                 }];

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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