I want to show the status bar in my app in all views but one. I have tried modifying the 'status bar is initially hidden' in the plist, i have tried:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
That hides the bar but leaves an ugly blue box where the status bar was (which isn't part of my view, there's nothing blue on there).
I have also tried altering the layout wants full screen and status bar settings in the 'interface builder' bit of Xcode 4.2.
Any suggestions?
EDIT - SORT OF SOLUTION:
I have done it by including:
-(void)viewWillDisappear:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
-(void)viewDidAppear:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}
on every single page that I want the status bar to be on.
It still looks choppy and rubbish because the tab bar appears and reappears each time you switch a view. But i've had enough, worked on this stupid problem for about 5 hours now so this will have to do.
SECOND EDIT -
Fixed the choppyness by including setStatusBarHidden=NO in viewWillAppears. God knows how everything works but it does.
Try This one It will Run perfectly..
[[UIApplication sharedApplication] setStatusBarHidden:YES];
And in XIB set none option for the status bar.
for iOS 7.
Go to info.plist and add two attributes if not present. set "Status bar is initially hidden" to "YES" and set "UIViewControllerBasedStatusBarAppearance" to "NO". This will hide status bar for your app.
#pragma mark - Hide statusbar
-(void)hideStatusBar {
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
// iOS 7.0 or later
[self setNeedsStatusBarAppearanceUpdate];
#else
// less than 7
[[UIApplication sharedApplication] setStatusBarHidden:YES];
#endif
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
If there is anyone looking for a solution where the above solution does not work (and there is still an annoying blue 20px gap at the top), try putting this in the viewWillAppear on the implementation file of the view controller that you would like the status bar to be hidden.
self.navigationController.navigationBar.frame = CGRectOffset(self.navigationController.navigationBar.frame, 0.0, -20.0);
That literally took me 12 hours or so to fix, and that was the solution, so now i'm spreading the word in case anyone else has this annoying issue.
Kartik's solution worked for me.
[[UIApplication sharedApplication] setStatusBarHidden:YES];
I added this to viewWillAppear: instance method.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.webView.scalesPageToFit = YES;
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.google.co.uk"]]];
}
And I spent ages on this too. Using Xcode 4.2, iOS5 sim.
But when I first implemented it, the annoying "space" at the top was there. I selected the View Controller in the storyboard and set the properties as follows:
Size: Full Screen
StatusBar: None
everything else inferred.
I checked wants full screen.
Voila, it all worked fine.
I know this is an old question but none of this answers works for me, so this is how it works for me to hide the status bar in a single viewController
First in your parentViewController you have to set:
- (UIViewController *)childViewControllerForStatusBarHidden {
if ( hideStatusBarViewController ) {
return hideStatusBarViewController;
}
return nil
}
It only returns the child view controller when its created otherwise nil is the default. When you add your hideStatusBarViewController you must call
[self setNeedsStatusBarAppearanceUpdate];
on the parentViewController, this function forces to read childViewControllerForStatusBarHidden. Finally in hideStatusBarViewController you must set
- (BOOL)prefersStatusBarHidden {
return YES;
}
Its the only solution that works for me. I hope it help somebody.
I would suggest you a different approach: insert that view onto the application's window:
YourUIAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.window insertSubview:self.yourView atIndex:([[appDelegate.window subviews]count])];
That way it will show over the status bar
I hope it helps you
This is solution if you want to hide status bar on a single view
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[self.view sizeToFit];
}
Here is a snippet of code that might help. When the view loads show the status bar, when you leave the view hide it again.
-(void)viewWillAppear:(BOOL)animated {
if([[UIApplication sharedApplication] respondsToSelector:#selector(setStatusBarHidden: withAnimation:)])
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
else
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
}
-(void)viewWillDisappear:(BOOL)animated {
if([[UIApplication sharedApplication] respondsToSelector:#selector(setStatusBarHidden: withAnimation:)])
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
else
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
}
The [[UIApplication sharedApplication] setStatusBarHidden:BOOL]; is enough, but:
Remember to set it back to NO before leaving the view or the page you return to will likely have the Nav Bar under the status bar.
Make sure that you set both status bar hide and show in the view in which you want the status bar hidden. I did the switch off in the viewDidLoad method, and - crucially - the switch back on in the viewWillDisappear:animated method. Any later and you're in for trouble.
Related
I am using MSNavigationPaneViewController from here and have rotation sort of working.
I've overridden the rotation methods in my root UINavigationController
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.topViewController != nil) {
return [appDelegate.topViewController supportedInterfaceOrientations];
} else {
return UIInterfaceOrientationMaskPortrait;
}
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.topViewController != nil) {
return [appDelegate.topViewController preferredInterfaceOrientationForPresentation];
} else {
return UIInterfaceOrientationPortrait;
}
}
which I push the MSNavigationPaneViewController with using presentViewController: animated:completion: and I have rotation working so certain views can have different orientations. The problem is, each view that has a different orientation needs the user to tilt the phone to change the orientation at which point it locks on the correct orientation.
I've done tons of reading to get this working and it seems I need preferredInterfaceOrientationForPresentation to fire before each view is loaded, but it's not firing.
I think it's not firing because the MSNavigationPaneViewController isn't changing view controllers using presentViewController.
This is the code used by MSNavigationPaneViewController to change the view
- (void)setPaneViewController:(UIViewController *)paneViewController
{
if (_paneViewController == nil) {
paneViewController.view.frame = _paneView.bounds;
_paneViewController = paneViewController;
[self addChildViewController:_paneViewController];
[_paneView addSubview:_paneViewController.view];
[_paneViewController didMoveToParentViewController:self];
} else if (_paneViewController != paneViewController) {
paneViewController.view.frame = _paneView.bounds;
[_paneViewController willMoveToParentViewController:nil];
[self addChildViewController:paneViewController];
void(^transitionCompletion)(BOOL finished) = ^(BOOL finished) {
[_paneViewController removeFromParentViewController];
[paneViewController didMoveToParentViewController:self];
_paneViewController = paneViewController;
};
[self transitionFromViewController:_paneViewController
toViewController:paneViewController
duration:0
options:UIViewAnimationOptionTransitionNone
animations:nil
completion:transitionCompletion];
}
}
which looks like it's just switching the viewController and therefor not calling preferredInterfaceOrientationForPresentation
Is there any way to force preferredInterfaceOrientationForPresentation to be called, or to trick it into be called maybe by a hidden view?
Thanks
EDIT ----
I totally understand how the new rotation system works in iOS6 and that it's down to the root to manage it. However preferredInterfaceOrientationForPresentation only seems to be called if the next view is being presented with one of the correct methods. Not if the window is just switched.
So I do actually need a way to trick this to be called.
You can trick the window into re-valuating its supported interface orientations by resetting its rootViewController.
UIApplication *app = [UIApplication sharedApplication];
UIWindow *window = [[app windows] objectAtIndex:0];
UIViewController *root = window.rootViewController;
window.rootViewController = nil;
window.rootViewController = root;
You'd need to make sure that when this code executes, -supportedInterfaceOrientations of the root view controller returns the proper mask (corresponding to how you want to force the orientation).
Be aware, this hack can cause a quick flash on the screen and glitch any ongoing animations.
preferredInterfaceOrientationForPresentation will not be called on controllers within a UINavigationController.
You are going to have to subclass UINavigationController and then implement this feature yourself. You'd simply want to delegated to topViewController.
For reference check out: http://code.shabz.co/post/32051014482/ios-6-supportedorientations-with-uinavigationcontroller
I also found this implementation of a UINavigationController subclass: https://gist.github.com/3842178
I am hiding the status bar in my application when I present my uiimagepickerviewcontroller modally.
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
In the callback method:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
I execute the following methods:
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
before calling:
[picker dismissViewControllerAnimated:YES completion:^() {}];
I've tried "showing" the status bar in the completion block to no avail. How should I go about in getting the status bar to reappear after dismissing my uiimagepickerviewcontroller?
Try putting it back in the view controllers dismissal completion handler:
[picker dismissViewControllerAnimated:YES completion:^(BOOL done){
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
}];
Although this is strange, there isn't any reason as to why this wouldn't be working jumping out at me.
I had the same problem in iOS 11. I could make the statusBar re-appear in the following way:
In Info.plist, set View controller-based status bar appearance to YES:
In the view controller that presents the UIImagePickerController, implement
- (BOOL)prefersStatusBarHidden {
return NO;
}
I have a App works well on iOS 4.3.3. But I found there are some problems on iOS 5. This App plays mp3 files by avaudioplayer and the remote control does not work well on iOS 5.
There are four view controllers in this App. I add following codes on each view controller in order to realize the function of remote control. The problem is, when the view controller is first time to open. The remote control button works well, even the app run in background or lock the screen. But when I click anther view controller and go back the previous on, the remote controller does not work anymore. But canBecomeFirstResponder function was called every time.
I even try to put
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
in delegate function
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
It not work.
I don't understand why this is happening. It tortured me for few days.
Is there better way to realize remote control function in multiple view controllers?
BTW, I added the UIBackgroundModes audio key to the info.plist. And this App works well well in background.
Any help will be appreciated.
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (void)viewWillAppear:(BOOL)animated {
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
}
- (BOOL) canBecomeFirstResponder {
NSLog(#"Can be first responder!");
return YES;
}
- (void)remoteControlReceivedWithEvent:(UIEvent *)event
{
if (event.subtype == UIEventSubtypeRemoteControlTogglePlayPause) {
NSLog(#"UIEventSubtypeRemoteControlTogglePlayPause");
[self playAndpause:nil];
}
}
I have created a simple navigation application. I allow all orientations for the application.
Problem is as follows
I am in landscape orientation. then i navigate from RootViewController to a UIViewController For showing the PDF. When I am in UiviewControoler i change orientation to portrait. and come back to the RootViewController. At this time the RootViewController is in landscape mode itself and it Shows whole UI badly.
I really do not know what to search on net. still i tried to search but couldn't got my answer.Can anyone tell me How to fix this problem?
First You declare Boolean type variable in app delegate file and then set property and synthesize in .m file. In app-delegate.m file u
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
MidwestTestAppDelegate *appDelegate = (MidwestTestAppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.isLandscapeLeft = TRUE;
}
else
{
MidwestTestAppDelegate *appDelegate = (MidwestTestAppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.isLandscapeLeft = FALSE;
}
}
in .m file u use this function which give u orientation is enable or not. similarly u do for view controller.
I have a UIViewController whose view is a UIWebView with an embedded movie. When the movie is playing full screen, and the device is rotated, the title bar ends up behind the status bar after the movie is dismissed. Why might this happen?
Turns out that the animation of the view controller's view wasn't finished when the video started. This caused it to be redisplayed over the video player view.
My solution:
(void)viewDidLoad
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:NO];
[UIApplication sharedApplication].keyWindow.frame=CGRectMake(0, 20, 320, 460);
self.navigationController.navigationBar.hidden=NO;
}
did you autoresizingMask on the UIWebView
webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleWidth);
and
-(BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) orientation
{
return YES;
}
It's no way to resolve this problem using MPMoviePlayerNotification, because UIWebView Video Don't use MPMoviePlayerViewController or it's private for developer.
But, there's another way to fix this bug.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(handleStatusBarFrameDidChange)
name:UIApplicationDidChangeStatusBarFrameNotification
object:nil];
- (void)handleStatusBarFrameDidChange {
self.navigationController.navigationBarHidden = YES;
self.navigationController.navigationBarHidden = NO;
}