I have an application with status bar hidden. For hiding status bar I did following things:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
This was working with ios 6. Now in iOS 7 I added View controller-based status bar appearance = NO.
I also created subclass of my navigation controller and added:
- (BOOL)prefersStatusBarHidden
{
return YES;
}
Everything is working well but when I present UIImagePicker status bar goes visible and than it never hides back even after dismissing view. I also added prefersStatusBarHidden method in the related view too but no success :(
Any help please.
Use following link
- (void)imagePickerController:(UIImagePickerController *)aPicker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// for iOS7
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)]) {
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
Following are the list of reference regarding status bar issues in ios7 on stack overflow Itself. ;-)
Status bar and navigation bar appear over my view's bounds in iOS 7
Status bar won't disappear
Status bar appear over my view's bounds in iOS 7
Use can use this method for status bar Issue.It should work fine.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 320, 20);
addStatusBar.backgroundColor = [UIColor colorWithRed:0.973 green:0.973 blue:0.973 alpha:1]; //change this to match your navigation bar
[self.window.rootViewController.view addSubview:addStatusBar];
}
Try this in your Target's general settings.
Related
I have created an application using XIB without Status Bar before for iOS7, now i need to add Status bar on my app and Status bar background color should same as Navigation bar background color. So i have tried like (In my info.plist) :
1) Set View controller-based status bar appearance to NO
2) Set Status bar style to UIStatusBarStyleLightContent
here is my code for App Delegate:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
[[UINavigationBar appearance] setBarStyle:UIBarStyleDefault];
[[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithRed:(51/255.0) green:(51/255.0) blue:(51/255.0) alpha:1.0]];
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:(51/255.0) green:(51/255.0) blue:(51/255.0) alpha:1.0]];
So i am getting the output like the below image :
also i am getting misplacement of UIButtons that i have given below in my screen (It's hiding 20 pixels).
Can you please help me that how can i fix this issue? I need my output like the below image :
Any help will be very appreciated, Thanks.
Third screen :
Add following code in your viewDidLoad method :
float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
if (systemVersion >= 7.0)
{
self.edgesForExtendedLayout = UIRectEdgeNone;
}
Please define this in AppDelegate.h (or) constants.h
#define isIOS7 ([[[UIDevice currentDevice]systemVersion]floatValue] >=7.0)?YES:NO
under viewDidLoad Write this lines.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 320, 20);
addStatusBar.backgroundColor = [UIColor colorWithRed:0.973 green:0.973 blue:0.973 alpha:1];
//change this to match your navigation bar
[self.window.rootViewController.view addSubview:addStatusBar];
}
OR we can change it manually in the xib.
By moving each element 20px down.
Surprise at how few people have suggested this. Here is the correct way (no hacking)
First, make your navigationBar have a Y origin of 20.
Then in the .h file, set your ViewController as a UIBarPositioningDelegate:
#interface XYZViewController : UIViewController <UIBarPositioningDelegate>
And in the .m file:
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationBar.delegate = self;
}
- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar {
return UIBarPositionTopAttached;
}
I tried to hide status bar in iOS7 by putting this:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
in delegate or in mainview
But it's not working!
It was working in iOS6
Either set "View controller-based status bar appearance" to NO in your info plist or add this code in your view controllers:
-(BOOL)prefersStatusBarHidden
{
return YES;
}
Add the following to your Info.plist:
UIStatusBarHidden
UIViewControllerBasedStatusBarAppearance
or follow this link http://www.openfl.org/developer/forums/general-discussion/iphone-5ios-7-cant-hide-status-bar/
In a viewController where you want to hide status bar add:
- (BOOL)prefersStatusBarHidden
{
return YES;
}
In viewDidLoad
[self prefersStatusBarHidden];
[self performSelector:#selector(setNeedsStatusBarAppearanceUpdate)];
In app *-info.plist
View controller-based status bar appearance set to YES
Try this.
In your iOS target -> Info, add View controller-based status bar appearance and set the value as NO.
It worked for me in iOS7. I have also set "status bar initially hidden" property to YES
//viewDidload
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
[self prefersStatusBarHidden];
[self performSelector:#selector(setNeedsStatusBarAppearanceUpdate)];
} else {
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
}
// Add this Method
- (BOOL)prefersStatusBarHidden
{
return YES;
}
this wil work ..hope it helps
In your apps plist file add a row call it " UIViewControllerBasedStatusBarAppearance" and set it to NO
from http://www.openfl.org/developer/forums/general-discussion/iphone-5ios-7-cant-hide-status-bar/, mgiroux's solution
In the Plist add the following properties.
Status bar is initially hidden = YES
View controller-based status bar appearance = NO
now the status bar will hidden.
I am working on storyboard based application (iPhone). Application has a Navigation Controller to start with. We are integrating an existing application with it. Thus we need to load the NIB file on click of a button.
NSBundle *someBundle = [NSBundle category_bundle ];
MainWindow *aViewController = [[MainWindow alloc]
initWithNibName:nibName
bundle:someBundle];
[self.navigationController pushViewController:aViewController animated:YES];
The existing application then loads another VC.
[[self navigationController] pushViewController:mySecondView animated:YES];
This view again comes from NIB.
This view then uses a singelton to get the instance of MainWindow (loaded in first step) and request it to show a modal view. "Bad Design" but I can not change it as this is an existing application and I need to deliver the integration tomorrow.
Modal is shown as -
[self presentModalViewController:aModal animated:YES];
We are opening the modal in landscape and for that in its viewWillAppear we are using this code-
[UIApplication sharedApplication].statusBarOrientation = self.interfaceOrientation;
and in viewDidDisappear
if (SYSTEM_VERSION_LESS_THAN(#"5.0")) {
[UIApplication sharedApplication].statusBarOrientation = self.parentViewController.interfaceOrientation;
} else {
[UIApplication sharedApplication].statusBarOrientation = self.presentingViewController.interfaceOrientation;
}
Question:
The problem is that UIView of MainWindow moves up by 20px after the modal pop up has been closed. I have tried to reset the frame. Also tried to hide the status bar but then status bar partially hides the navigation bar, to resolve this we tried to hide the navigation bar after the status bar has been made visible and then showing it again, but with no success.
Please let me know how can I resolve this issue.
I am running an "iPhone-only" app in the iPad simulator...When the orientation of the device is changed to landscape mode, I have a view controller that kicks in and programmatically loads a WebView. This works swimmingly in the iPhone (no gap on top of landscape view), but when simulating in the iPad, there's a 20px (I think?) gap at the top of the view.
Here's the code in the landscape view controller's viewDidLoad where I load the WebView:
[super viewDidLoad];
// Initialize webview and add as a subview to LandscapeController's view
CGRect webFrame = [[UIScreen mainScreen] bounds]; // Use bounds to take up entire screen
self.myWebView = [[[UIWebView alloc] initWithFrame:webFrame] autorelease];
self.myWebView.scalesPageToFit = YES;
self.myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.myWebView.delegate = self;
[self.view addSubview: self.myWebView];
// remove status bar from top of screen
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
Setting the status bar to default, has no influence.
I can't seem to figure out why this would be fine on the iPhone, but emerge on the iPad???
Any ideas? Thanks in advance!
The screen bounds are in screen coordinates. You're adding the webview as a subview of self.view; its frame is in self.view coordinates. You want to fill your view, not the screen (your view is automatically resized by UIViewController/the rest of UIKit, which should end up resizing the web view to to auto-resizing):
self.myWebView = [[[UIWebView alloc] initWithFrame:self.view.bounds] autorelease];
It's not safe to change the status bar in -viewDidLoad. View-loading can happen anywhere (it happens when anything calls viewController.view). I'm also not sure why you're setting the style; you want to set hidden-ness:
In -viewWillAppear:, do [application setStatusBarHidden:YES animated:animated];
In -viewWillDisappear:, do [application setStatusBarHidden:NO animated:animated];
Finally, you might be seeing different behaviour because the iPad is running OS 3.2.x and the phone is running 3.1.x or 4.x. Additionally, the iPhone-compatibility mode uses a dummy status bar; the "real" status bar always stays at the edges of the screen.
20 pixels at the top is almost always invariably related to the height of the status bar.
The code you posted looks fine... for setting up the UIWebView. But you're adding it as a subview to your view controller's view. How is that sized? What is its frame?
I finally figured this out. The key missing component, which I didn't mention in the original post, is that the view controller that manages landscape is actually implemented as a modal view. (See the View Controller User Guide for code on how to do this) In concept, I have a Portrait view controller. (which is the primary controller) In the Portrait view controller's viewDidLoad I apply for a Notifier that is triggered off of a change in the orientation like so:
- (void)viewDidLoad {
[super viewDidLoad];
// SECTION to setup automatic alternate landscape view on rotation
// Uses a delegate to bring the landscape view controller up as a modal view controller
isShowingLandscapeView = NO;
// Create Landscape Controller programmatically
self.landscapeViewController = [[LandscapeViewController alloc] initWithNibName:#"LandscapeViewController" bundle:[NSBundle mainBundle]];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
// END SECTION landscape modal view controller
Then, when orientation changes this method is called:
- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
{
// Load Landscape view
landscapeViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:self.landscapeViewController animated:YES];
isShowingLandscapeView = YES;
}
At the same time I was removing the status bar from the Landscape view controller's viewWillAppear method:
- (void)viewWillAppear:(BOOL)animated
{
// remove status bar from top of screen
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:animated];
self.myWebView.delegate = self; // setup the delegate as the web view is shown
}
and this is where the problem is introduced. The Portrait view controller captures the screen dimensions, before transitioning to landscape as a Modal View. Then, viewWillAppear, in the Landscape view controller, removes the status bar.
So, the solution is to move the
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:animated];
statement to the orientationChanged method in the Portrait view controller, BEFORE transitioning to the Landscape Modal View.
- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
{
// remove status bar from top of screen
// NOTE: this must be declared BEFORE presenting the Modal View!!!! If it's not, the landscape view will
// contain an ugly white bar in place of the missing status bar at the top of the view.
[[UIApplication sharedApplication] setStatusBarHidden:YES];
// Load Landscape view
landscapeViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:self.landscapeViewController animated:YES];
isShowingLandscapeView = YES;
}
Note, that as tc helpfully mentioned above, if you want the status bar to appear when orienting back to Portrait, then you need
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:animated];
in the viewWillDisappear method in the Landscape view controller.
I have a tab bar with two views. In the first view the iPhone status bar is hidden using [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES]. When the second view is loaded, and the status bar is made visible again using [[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES] it overlaps the view. How do I make the status bar visible again without overlapping the second view?
Thanks
Try this code.
The dot is a dash..
(void)viewWillAppear:(BOOL)animated {
// to fix the controller showing under the status bar
self.view.frame = [[UIScreen mainScreen] applicationFrame];
}