3

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;
}
Community
  • 1
  • 1
Mahmoud Adam
  • 5,772
  • 5
  • 41
  • 62
  • 1
    Please post up some code so that we can see what might be wrong. – WhoaItsAFactorial May 15 '12 at 11:06
  • 1
    Yes, add the code, that you use and that makes it not appear. – Denis Kutlubaev May 15 '12 at 11:14
  • Moving the StatusBar to the bottom of the device is against Apple's Human Interface Guidlines. It might be best if you use a different UI element for showing tht content. Consider looking at how the Mail app does it. – Sam Spencer May 15 '12 at 11:42
  • i'm not moving the status bar to bottom, i'm using a new status bar and place it to the bottom of the screen and the default one will be the same, so i used extends from UIWindow but the problem that it didn't appears neither in top nor bottom – Mahmoud Adam May 15 '12 at 12:29

1 Answers1

2

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.

Fostah
  • 11,398
  • 10
  • 46
  • 55