How to make status bar reappear after dismissing uiimagepickerviewcontroller - iphone

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;
}

Related

ios 7 document interaction controller hide status bar

In my iOS app i've hidden the status bar with this code in each ViewController:
- (BOOL)prefersStatusBarHidden
{
return YES;
}
In a view I need to use a UIDocumentInteractionController, but when it comes up, the status bar appears, is there a way to keep it hidden?
Thanks in advance
Use a combination of the following code and the code from iOS:
- (UIViewController *) documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *) controller {
// hack to keep status bar visible
[[NSOperationQueue mainQueue] addOperationWithBlock:
^{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}];
return self;
}
combined with
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller {
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
Try this works for me :
- (void)documentInteractionControllerWillBeginPreview:(UIDocumentInteractionController *)controller
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
Set documentController.delegate to self and use
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller {
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}

iPhone - Remove status bar programmatically

I have made an app that implements the iPhone's camera.
When the user finishes picking their image, the status bar reappears!
How would I make sure that the status bar stays hidden?
Here is my code:
-(IBAction)pickImage:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
background.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
If i am doing anything wrong, please point it out!
Thanks,
Rafee
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
You may opt for another animation style if at all.
In iOS 7, there is a method on UIViewController, "prefersStatusBarHidden". To hide the status bar, add this method to your view controller and return YES:
- (BOOL) prefersStatusBarHidden
{
return YES;
}
In this case,We are using 2 steps
In first step:
Add in info.plist: "View controller-based status bar appearance" with value "NO"
In Second step: Use/call this code with delegate of UIImagePickerController
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if([navigationController isKindOfClass:[UIImagePickerController class]])
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
With iOS 7 and later, you can use the following code to hide and unhide the status bar,
#interface ViewController()
#property (nonatomic, getter=isStatusBarHidden) BOOL statusBarHidden;
#end
#implementation ViewController
... other codes
- (BOOL)prefersStatusBarHidden {
return self.isStatusBarHidden;
}
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
return UIStatusBarAnimationFade;
}
- (void)hideStatusBar {
self.statusBarHidden = YES;
[self setNeedsStatusBarAppearanceUpdate];
}
- (void)showStatusBar {
self.statusBarHidden = NO;
[self setNeedsStatusBarAppearanceUpdate];
}
#end
There seems to be a bug in the dismiss mechanism of UIViewController associated with UIImagePicker, with a sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum.
The moment of the call to dismissModalViewController (plus the method with completion:) the UIApplication's status bar hidden property instantly changes from YES to NO, and it is drawn at the moment of stepping over dismiss...
This is only really obvious for apps that use a full-screen view. My current app project does, plus I control the frame of the view controller's view before presenting, so the UIImagePicker is NOT full screen. This made the bug VERY obvious. I spent 4-5 hours determining the cause, and this was the final certain conclusion, and the bug does NOT occur for sourceType Camera nor PhotoLibrary.
So if you want a perfectly full-screen app and want to present a bug-free UIImagePicker, avoid UIImagePickerControllerSourceTypeSavedPhotosAlbum
Grand central dispatch is your friend, using this method you won't see the status bar appear at all when the picker is displayed or afterwards
- (void)hideStatusBar
{
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)])
{
[self performSelector:#selector(setNeedsStatusBarAppearanceUpdate)];
}
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self hideStatusBar];
double delayInSeconds = 0.2;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self hideStatusBar];
});
}

Hide the status bar on iPhone on a single view?

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.

How do you start activity indicator?

I want to start an activity indicator whenever the user presses any link on a webview.
First assign the ViewController which the UIWebView appears in as its delegate: Do this either by control-dragging from the UIWebView to the File's Owner object in InterfaceBuilder or in code:
[myWebView setDelegate:myViewController];
Then in your ViewController.m file you can now use the delegate methods to detect when pages are being loaded. These delegate methods will be triggered every time a link or new page is loaded in the UIWebView.
- (void)webViewDidStartLoad:(UIWebView *)webView {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
If you wanna show network activity indicator just put
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
and then
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
when you wanna hide it
while if you needs UIActivityIndicator
you have to define it in your controller then Outlet it in XIB and then
show
[activityIndicator startAnimating];
hide
[activityIndicator stopAnimating];
Take a look at UIWebViewDelegate Protocol.
It will allow your delegate to be notified whenever the webview is starting to load new content, which, presumably, is the case whenever a link has been pressed. The delegate method you want is webViewDidStartLoad: - in its implementation you could then easily set up or start your activity indicator.
Use the method webViewDidStartLoad: in UIWebViewDelegate.

iOS SDK - How to get the status bar back when using UIImagePickerController?

As soon as I add a UIImagePickerController sub view to my view the status bar disappears and I can't get it back. Is there any way to keep the status bar visible?
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self.view addSubview:imagePicker.view];
[imagePicker viewWillAppear:YES];
[imagePicker viewDidAppear:YES];
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];
I had to do the same thing in a camera app as well. Apparently, in addition to setting the status bar to not be hidden, you also have to reset its style after the camera view makes it disappear. Try this:
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
The accepted answer's solution got deprecated meanwhile.
Use
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
instead of
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];
Valid values for the animation parameter are UIStatusBarAnimationNone, UIStatusBarAnimationFade, UIStatusBarAnimationSlide. Details are found in the documentation.
After reading this and finding none of the answers worked, I managed to get it working by doing the following:
• Setting a delegate for the UIImagePickerController
• In that delegate, hide the status bar in the delegate's navigationController:didShowViewController:animated: function.
E.G:
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}
Add your UIImagePicker to the root view (i.e. a Navigation Controller or TabbarController)
[self.tabBarController presentModalViewController:imagePickerController animated:YES];
After that you can use
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
// do your stuff
[picker dismissModalViewControllerAnimated:YES];
}
to close your ImagePicker.
well, I know you are not supposed to do this, but if you subclass UIImagePickerController, you can put that in your custom class:
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
}
None of the solutions worked on iOS 5.1.1
Tim's solution worked on iOS 4.2.1
The only way I was able to fix the problem on iOS 5.1.1 was like that
-(void)viewDidAppear:(BOOL)animated
{
double delayInSeconds = 0.01;
dispatch_time_t popTime =
dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[[UIApplicationsharedApplication] setStatusBarHidden:NO];
});
which is very hacky and wrong.
I spent half a day looking for a solution and then decided to just use AVFoundation approach and it took me an hour to implement the same basic photo capture that I needed using AVCaptureSession and AVCaptureStillImageOutput. And it works better too - AVCaptureSession starts faster than UIImagePickerController and AVCaptureVideoPreviewLayer has a much better frame rate on modern devices compared to UIImagePicker camera preview.