iOS Hidding status bar on a modal view - ios

I'm trying to display a full image on screen, by pushing a modal view, with the full image, i managed to do that with no problem, but for some reason i cannot hide the status bar on the modal, i'm presenting the modal from a didSelectItemAtIndexPath of a collection view, i'm trying to hide the status bar, before calling the presentViewController, here's the code:
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSArray *infoPhoto = self.imagesFromCD[indexPath.row];
// NSLog(#"Info photos = %#", infoPhoto);
NSString *imageName = [[self.imagesFromCD valueForKey:#"imgNameCD"]objectAtIndex:indexPath.row];
UIImage *imageToPass = [self getImageFromDocuments:imageName];
displayImageViewController *displayVC = [[displayImageViewController alloc]init];
displayVC.modalPresentationStyle = UIModalPresentationCustom;
displayVC.transitioningDelegate = self;
displayVC.foto = infoPhoto;
displayVC.imageToDisplay = imageToPass;
UIApplication *myapp = [UIApplication sharedApplication];
[myapp setStatusBarHidden:YES withAnimation:YES]; // Heres where the bar should be hidden.
[self presentViewController:displayVC animated:YES completion:nil];
}
I also tried to add the:
-(BOOL)prefersStatusBarHidden {
return YES;
}
Inside the Modal .m file, but nothing happened.

First of all set in your info.plist View controller-based status bar appearance is equal to no and than use below where ever you want to status bar hidden or not:
[[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationFade];
[[UIApplication sharedApplication] setStatusBarHidden:NO
withAnimation:UIStatusBarAnimationFade];

Related

iOS: StatusBar appearance error

I have first ViewController with Portrait orientation and second ViewController with landscape orientation. The first ViewController have status bar, the second have not.
Then I present second ViewController from the first ViewController, it presenting with out status bar. Then I dismiss it I go back to first ViewController and have my status bar, but the position of the View is incorrect.
View position like screen have not status bar. How can I update it?
first, try this:
In your landscape VC declare the following:
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:true];
// you can also try to hide the status bar with animation:
[[UIApplication sharedApplication] setStatusBarHidden:true withAnimation:UIStatusBarAnimationSlide];
}
In your portraint VC declare the following:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:false];
// you can also try to show the status bar with animation:
[[UIApplication sharedApplication] setStatusBarHidden:false withAnimation:UIStatusBarAnimationSlide];
}

How do I hide the status bar of a pushed view controller in objective c?

I have a signup form that pops up when a button is tapped.
My aim is to hide the status bar when this modal is popped up.
Here is my code:
- (IBAction)tappedJoinButton:(id)sender {
if (![PFUser currentUser]) {
PFSignUpViewController *signUpViewController = [[PFSignUpViewController alloc] init];
[signUpViewController setDelegate:self]; // Set ourselves as the delegate
// Present the sign up view controller
[self presentViewController:signUpViewController animated:YES completion:NULL];
}
}
I have set View controller-based status bar appearance to yes in my plist file. Now I'd like to choose where I hide the status bar. In this situation I'd like to hide it in the signUpViewController that pops up.
I haven't seen any answers on here showing how to hide it in a pushed view controller.
How do I achieve this?
Kind regards
If you want to hide status bar for only one ViewController the do this:
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[super viewWillDisappear:animated];
}
For your case it will be in PFSignUpViewController.
Hope this helps .. :)
Try this code
in viewDidload of PFSignUpViewController
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
[self performSelector:#selector(setNeedsStatusBarAppearanceUpdate)];
} else {
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
paste this function in controller
- (BOOL)prefersStatusBarHidden {
return YES;
}
you lust like ....
if ([UIApplication sharedApplication].statusBarHidden != hideStatusBar)
{
[[UIApplication sharedApplication] setStatusBarHidden:hideStatusBar withAnimation:UIStatusBarAnimationSlide];
}
Write this in your viewWillAppear...
[[UIApplication sharedApplication] setStatusBarHidden:YES];
Or try This method ....
-(void)navigationController:(UINavigationController *)
navigationController willShowViewController:(UIViewController *)
viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
Add this "View controller-based status bar" appearance in the plist and set NO
[[UIApplication sharedApplication] setStatusBarHidden:YES];

Status bar appears again after showing MPMediaPickerController modal

I hid status bar in my app by setting [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; and by this code:
- (BOOL)prefersStatusBarHidden
{
return YES;
}
By when I show the MPMediaPickerController modal with [self presentViewController:mpMediaPlayerController animated:YES completion:^{}];, the status bar is being show again.
How can I hide it?
Subclass the MPMediaPickerController and add:
- (BOOL)prefersStatusBarHidden {
return YES;
}
After getting back from MPMediaPlayerController again hide status bar in ViewWillAppear method
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
Hope it will work.

Tap Gesture to Hide Navigation Bar, Tab Bar, and Status Bar

I am trying to implement a tap gesture on my web view to hide/show the navigation bar, tab bar, and status bar. I have the hiding/showing of the navigation bar working fine and I can hide the status bar but not get it to show back up. The tab bar items get hidden but the bar is still there. Can anyone help with this?
- (void)toggleBars:(UITapGestureRecognizer *)gesture
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
BOOL statusBarHidden = YES;
BOOL barsHidden = self.navigationController.navigationBar.hidden;
[self.navigationController setNavigationBarHidden:!barsHidden animated:YES];
BOOL tabBarHidden = self.tabBarController.tabBar.hidden;
[self.tabBarController.tabBar setHidden:!tabBarHidden];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIBarButtonItem *systemAction = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:#selector(showMenu)];
self.navigationItem.rightBarButtonItem = systemAction;
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(toggleBars:)];
[webView addGestureRecognizer:singleTap];
singleTap.delegate = self;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
EDIT: It looks like the tab bar is hiding but my webview just isn't filling the empty space. How can I have it fill the space when the tab bar is hidden?
First of all, your status bar never unhides because you never tell it to. As written your code merely tells the status bar to hide every time it is executed.
[[UIApplication sharedApplication] setStatusBarHidden:![[UIApplication sharedApplication] isStatusBarHidden] withAnimation:UIStatusBarAnimationSlide];
[self.navigationController setNavigationBarHidden:!self.navigationController.navigationBar.hidden animated:YES];
Additionally, I'm not sure about the details of why your tab bar isn't hiding properly, but I did find the following category which claims to be able to hide the tab bar with option animation.
https://github.com/idevsoftware/Cocoa-Touch-Additions/tree/master/UITabBarController_setHidden
I got the status bar to hide/show by adding this to my toggleBars method, but I still haven't figured out why the tab bar items hide but not the tab bar itself.
if (([UIApplication sharedApplication].statusBarHidden = YES))
{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
}
else
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}

Present multiple Images in fullscreen

I'm looking for the name of the class Apple uses to present a number of Images in full screen (similar to the AppStore-App on iPad when you tap the preview images of any App. In the bottom of the view is a bar with little preview Images from all the Images).
If this is a public class, how is it called and is it available for iPhone as well?
Ok so I have created my own ImageFullScreenPresenter.
What is important for anybody trying to build their own ImageFullScreenPresenter is to make it a subclass of UIViewController.
PKImageFullScreenPresenter *pkImageFullScreen = [[[PKImageFullScreenPresenter alloc] initWithNibName:#"PKImageFullScreenPresenter" bundle:nil imageArray:myImageArray] autorelease];
AppDelegate *appDel = (AppDelegate *)[UIApplication sharedApplication].delegate;
UIViewController *rootViewController;
if (DEVICE_IS_IPAD) {
//since the splitviewcontroller is the rootviewcontroller on ipad i set it as my temporary rootViewcontroller for ipad
rootViewController = appDel.splitViewController;
}
if (DEVICE_IS_IPHONE) {
//on iphone i need the tabbarcontroller as temporary rootviewcontroller
rootViewController = appDel.tabBarController;
}
//set the alpha to zero, so it can fade in animated
pkImageFullScreen.view.alpha = 0;
//save the temporary rootViewController, so I can set it back when dissmissing the ImageViewController
pkImageFullScreen.superViewController = rootViewController;
//hide the status bar
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
//setting black backgroundcolor
[UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor blackColor];
//init the fullscreencontroller as rootview
[[UIApplication sharedApplication].keyWindow setRootViewController:[[[UINavigationController alloc] initWithRootViewController:pkImageFullScreen] autorelease]];
//smooth fade animation
[UIView animateWithDuration:.5f
animations:^(void){
pkImageFullScreen.view.alpha = 1;
}];
Doing so, allows me to present the ImageFullScreenPresenter on iPhone and iPad, no matter you are using a window-based app, a splitViewController on iPad or whatever.
When dismissing the ImageFullScreenPresenter i set the temporary saved rootViewController back with an animation:
- (void)closeView:(id)sender{
[UIView animateWithDuration:.5f
animations:^(void){
self.view.alpha = 0;
}completion:^(BOOL finished){
//show the statusbar again
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
//setting the statusbarstyle
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
//set the backgroundcolor for the window
[UIApplication sharedApplication].keyWindow.backgroundColor = GLOBAL_TINT_COLOR; //my custom color vor all GUI Objects
//set the temporary rootViewController back
[[UIApplication sharedApplication].keyWindow setRootViewController:superViewController];
//sometimes the navigationbar hides the statusbar, the following two lines help me out
[[UIApplication sharedApplication].keyWindow.rootViewController.navigationController setNavigationBarHidden:YES];
[[UIApplication sharedApplication].keyWindow.rootViewController.navigationController setNavigationBarHidden:NO];
}];
}
I dont know if this is the right way to go, but it works perfectly finefor me. I do not have to worry abput any rotation issues like I would have when i directly add this to [UIApplication sharedApplication].keyWindow.
I hope this helps others who try do achieve the same :)

Resources