Status bar when hidden navigation bar in iOS 7 - ios

I build app using UINavigationController is root view, i have issue hide navigation bar, when i hide navigation bar self.navigationController.navigationBarHidden = YES; status bar translucent not like status bar iOS 6 version like app Apple Store
How to fix it?
PS: I use UIBarPositionTopAttached to UIStatusBar like iOS 6

1.Add this line in your viewDidLoad to get default iOS6 style..
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque];
If you need default syle in whole app means try this.
info.plist
----> Status Bar Style
--->UIStatusBarStyle to UIStatusBarStyleBlackOpaque
2.Add following method to adjust status bar height in iOS7..
- (void)viewDidAppear:(BOOL)animated
{
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
if ([[UIDevice currentDevice].systemVersion floatValue] >= 7) {
CGRect windowFrame = [UIScreen mainScreen].bounds;
windowFrame.origin.y+=20.0;
windowFrame.size.height-= 20.0;
self.view.frame = windowFrame;
[self.view layoutIfNeeded];
}
}

you can directly set status bar black opaque through plist add this key in .plist file
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleBlackOpaque</string>
Thanks.

Related

Set status bar colour for different view controllers

I have 6 view controllers. I'd like to set the status bar of my first view controller to black and then the other 5 to white. All view controllers are in a push stack.
I've tried to implement
[self setNeedsStatusBarAppearanceUpdate]
- (UIStatusBarStyle) preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
That does not seem to work. I've also tried playing with the apps plist properties. Any ideas?
If you want to change Background colour of status bar then that's possible.
you have to change UIWindow 's background colour to your preferred colour. try following
e.g.
[[UIApplication sharedApplication].delegate window].backgroundColor = [UIColor orangeColor];
and if you want to change text colour then just try
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
You have missed this settings in Plist
View controller-based status bar appearance to YES
Do the following things.
View controller-based status bar appearance = NO in plist.
The ViewController that you want to make white in ViewwillApper add
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
The ViewController that you want to make Black in ViewwillApper add
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];

iOS status bar and UIView

There is UIView, status bar, iOS 7 and iOS 6.
With iOS 6 everything is good: my UIView (transparent, under "Tap to set destination" label) appears right below status bar. Here is the picture:
The problem is with iOS 7. Here:
I expect that UIView will be under status bar, not beneath it.
I have already tried to detect iOS version and if it's 7 or upper change UIView frame programmatically. But my UI with all the constraints made in storyboard... So it did not help. What can I do to resolve this problem?
UPD: maybe I really should make design more capable for iOS7? I'll think about it, and thanks for recommendations!
In your View Controller viewDidLoad, you should add:
if (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)) {
[self setEdgesForExtendedLayout:UIRectEdgeNone];
}
If you really really need to do this you can place the map view inside another view that will be the root view of the controller. This root view will be under the status bar in iOS 6 and take full screen in iOS 7. Set black background for the root view.
Add constrains from this root view to the map view and in viewDidLoad: check iOS version. In iOS 7 change top constrain from 0 to the status bar height (or add contain to topLayoutGuide and remove the top constrain).
But again the behavior you see is normal for iOS 7, and trying to make you view under the status bar you make your app look old-fashioned. May be it's time to reconsider you design.
In iOS 7 that's the default behavior of status bar. I guess the easiest solution will be to hide the status bar all together.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
[self prefersStatusBarHidden];
[self performSelector:#selector(setNeedsStatusBarAppearanceUpdate)];
} else {
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
}
// Add this Method
- (BOOL)prefersStatusBarHidden
{
return YES;
}
Try many ways, I saw dozens of post. Finally this is the best solution I found.
Proper way to hide status bar on iOS, with animation and resizing root view

Adding a subview above the status bar iOS 7

Ive got a small rectangular view that animates down from the top of my app. I need it to be at the very top of the screen and animate down over the status bar, however the animated view is appearing under the status bar. Anyone know how I can get it over the status bar??
here is what Im doing currently
[self.navigationController.view addSubview:self.headerView];
It works perfectly and is in the correct position EXCEPT for the fact its underneath the status bar. Any ideas?
edit: I know this is possible because snapchat does it.
One option you can do is, when you animating the headerView of yours,
take snapshot of the statusbar
hide statusbar
add subview of snapshot view on the statusbar position
do the header view animation over snapshot view
remove snapshot view and show statusbar again.
This way you can get nice animation which looks like it's doing over status bar.
Edit: I will try to explain in pseudo-code
// 1. take snapshot of the status bar
UIView* snapshotView = [[UIScreen mainScreen] snapshotViewAfterScreenUpdates:NO];
// 2. hide statusbar
_statusBarHidden = YES;
[self setNeedsStatusBarAppearanceUpdate];
// you need to set "View controller-based status bar appearance" option to yes on plist
- (BOOL)prefersStatusBarHidden
{
return _statusBarHidden;
}
// 3. add subview of snapshot view on the statusbar position
CGRect frame = self.view.frame;
frame.height = [[UIApplication sharedApplication] statusBarFrame].size.height;
[self.view addSubView:snapshotView];
// 4. do the header view animation over snapshot view
.. Just do the animation you already were doing
// 5. remove snapshot view and show statusbar again.
[snapshotView removeFromSuperview];
_statusBarHidden = NO;
[self setNeedsStatusBarAppearanceUpdate];

Window for an External Display affects primary screen

I create a new window when there is an additional screen (up to 2). Each window shows a different content, in a different screen.
The problem is under iOS7: Creating and showing this external window makes the status bar visible in the first one, which is also the main one. Then, the system adds some space (20points) to rearrange the top bar and some views. It does not work for me, because it's a custom bar.
Why is this happening and how may I stop the system to add the status bar?
This is the offending code:
- (void) handleScreenConnectNotification:(NSNotification*)notification
{
NSLog(#"screens=%# _secondWindow = %#",[UIScreen screens], _secondWindow );
if ( [[UIScreen screens] count] > 1) {
// Associate the window with the second screen.
// The main screen is always at index 0.
UIScreen * secondScreen = [[UIScreen screens] objectAtIndex:1];
CGRect screenBounds = secondScreen.bounds;
_secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
_secondWindow.screen = secondScreen;
_secondWindow.hidden = NO;
}
}
I have tried changing the _secondWindow's frame to a smaller area. Does not solve the issue.
To handle the status bar, the app is configured like this
Under the app property list: View controller-based status bar appearance = YES
I added this code for each view I do not want to show the status bar:
- (BOOL)prefersStatusBarHidden
{
return YES;
}
Because you mentioned the "View controller-based status bar appearance" - also try setting the "Status bar is initially hidden" to true.
<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
To correctly handle the case you don't want the status bar initially hidden, provide a rootViewController to your second window. This rootViewController must implement -(BOOL)prefersStatusBarHidden.

iOS 7 navigation bar of uinvigationcontroller issue

I have attached how UI looks on the different iOS versions.
This is my code below:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:contactsViewController];
[self.viewController presentModalViewController:navController animated:YES];
iOS 6
iOS 7
First problem is status bar in iOS 6 I have not status bar. Second problem is overdrawing two views. How to solve it?
You may wish to use a resizable image:
[image resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0) resizingMode:UIImageResizingModeStretch];
Or, as AliSoftware suggested, set the extended layout edges to UIRectEdgeNone (be sure to check if edgesForExtendedLayout is supported (your app will crash if it ties to assign this property running on iOS 6.x device):
if ([self respondsToSelector:#selector(setEdgesForExtendedLayout:)]) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
I would strongly invite you to read Apple's "UI Transition Guide" which explains all these differences between iOS6 and iOS7 and how to adapt your code accordingly.
The easiest way if you want your view to still be under your statusBar even in iOS7 is to set your UIViewController's self.edgesForExtendedLayout = UIRectEdgeNone in its viewDidLoad.
You can hide the status bar in the presented viewcontroller by writing this method
- (BOOL)prefersStatusBarHidden {
return YES;
}

Resources