Entering a UIView or UIWindow above the status bar

My goal is to draw an invisible button above the status bar at the top of my iPhone application (size 320 * 20 pixels).

No matter what I try, something is not good:

  • For example, I tried to create a new view. When I want to place a view at the top of my application, it always disappears behind the status bar, not in front of it!

  • I found another great idea in Stackoverflow: Add a UIView over all other views, including the StatusBar. Even if the second UIWindow is not recommended, I tried to implement it. It worked the way I wanted until I noticed a problem: the keyboard no longer appears when necessary (for example, when clicking in a text field)!

How can i fix this? Or is there a better approach to my problem? This is my code for creating a second window:

// Create window statusWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,320,20)]; statusWindow.windowLevel = UIWindowLevelStatusBar; [statusWindow makeKeyAndVisible]; // Create statusBarButton statusBarButton = [UIButton buttonWithType:UIButtonTypeCustom]; CGRect buttonFrame2 = statusBarButton.frame; buttonFrame2.size = CGSizeMake(320,20); statusBarButton.frame = buttonFrame2; [statusBarButton addTarget:self action:@selector(goTop) forControlEvents:UIControlEventTouchUpInside]; // Place button into the new window [statusWindow addSubview:statusBarButton]; 
+7
iphone uiview keyboard statusbar uiwindow
source share
4 answers

In the documentation for - [UIWindow makeKeyAndVisible]:

This is a convenient way to make the main window of the recipient and display it in front of other windows. You can also hide and open the window using the inherited hidden property UIView.

A “key window” is one that receives certain input events; text fields in a non-key window may not work. You can do two things:

  • Then call [window makeKeyAndVisible] in the old window window
  • Set statusWindow.hidden = NO instead (but I don't understand why it will be hidden by default). I do not think that you can "display it in front of other windows", for example, -makeKeyAndVisible; windows don't have a supervisor, you can call -bringSubviewToFront: on IIRC.
+8
source share

in the AppDelegate file

 self.window.windowLevel = UIWindowLevelStatusBar; 

or in any other class

 [AppDelegate appDelegate].window.windowLevel = UIWindowLevelStatusBar; 

and if you want the status bar to be on top, you can set

 self.window.windowLevel = UIWindowLevelNormal; 
+8
source share

If other users want to implement this, here is my solution:

 // Create window statusWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,320,20)]; statusWindow.windowLevel = UIWindowLevelStatusBar; // Dont make the statusWindow keyWindow or the keyboard won't work! // [statusWindow makeKeyAndVisible]; // Create statusBarButton statusBarButton = [UIButton buttonWithType:UIButtonTypeCustom]; CGRect buttonFrame2 = statusBarButton.frame; buttonFrame2.size = CGSizeMake(320,20); statusBarButton.frame = buttonFrame2; [statusBarButton addTarget:self action:@selector(goTop) forControlEvents:UIControlEventTouchUpInside]; // Place button into the new window [statusWindow addSubview:statusBarButton]; // Instead, add this: [window makeKeyAndVisible]; // has to be main window of app statusWindow.hidden = NO; // without this the statusWindow won't appear 
+7
source share

Try:

 [self.view bringSubviewToFront:statusWindow]; 

I do not think it is possible to make a presentation in front of the status bar.

0
source share

All Articles