Albert Renshaw
Albert Renshaw

Reputation: 17892

Show status bar AND prompt notification drop down

In iOS if you vertically swipe from off the screen onto the screen you will get the notification screen to drop down.

If you set your status bar to hidden (full screen app) then swipe down you get a prompt drop down "tab", which is so nice! (See screenshot below)

Is there anyway to show the status bar so the user can see the time and their service and battery percentage and everything, and then we ALSO have the prompt drop down "tab" display instead of it just automatically sliding down the entire notifications center?

enter image description here

Upvotes: 2

Views: 1141

Answers (2)

Albert Renshaw
Albert Renshaw

Reputation: 17892

In appDelegate you need to add a second UIWindow (property STRONG retain) that is the full size of your app with a clear background.

SET THE UIWINDOWS LEVEL TO: setWindowLevel:UIWindowLevelStatusBar+1.0f

Then you need to add a second VC and set it as the subview for the second UIWindow.

in that VC.m you do touchesBegan and if the location.y is in the area of the status bar's height times 2 (height*2 because you can pull notifications down from a little lower than the status bar it turns out) then you set the status bar to hidden and call prefersStatusBarHidden YES and setNeedsStatusBarAppearanceUpdate

*(Note you must create the new UIWindow and VC or else you won't be able to detect touchesBegan in the status bar location).

Then once touchesEnded or touchesMoved below that region you can make the status bar visible again.

This flashes the status bar for a split second and causes the triangles to appear.

Now move your whole app functionality into the second VC




Proof is in the pudding:enter image description here

Upvotes: 0

Gandalf
Gandalf

Reputation: 2417

I believe there is no direct mechanism, but a trick can be applied to achieve this. But again this won't give the exact solution what you are expecting here. But let me share my thoughts.

Implement the touchBegan method in a UIViewController subclass and Capture the starting point of touch event.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

UITouch *touch = [touches anyObject];

CGPoint startPoint = [touch locationInView:self.view];

Then you can compare the y coordinate value with 30/40 pixels(this is approx. pixel height in which app screen detects the event for notification pull)

if(startPoint.y <= 40) {

Now you can set the statusBarHidden property to NO

@Cautions: -

  • You need to set the property with a slight delay after touch event otherwise immediately it can pull down the notification view.
  • As soon as statusBar is visible your drop down is gone.
  • Also you need to make status bar hidden again after a certain time interval.
  • As this functionality should work from any screen(view) of the app, you may want to create a Category on UIViewController to avoid handling this in each and every class.
  • You should be careful with gesture handling since you override touchesBegan (see the Chain of Responsibility mechanism on the dev center)

Upvotes: 1

Related Questions