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];
}
Related
Hi,
I am using WEBKIT(STKWebKitViewController) for showing the url and i am unable to find a way to hide the navigation bar and bottom bar. Please let me know the solution.
Thanks
Just go through your STKWebKitViewController there is a method
self.navigationController.hidesBarsOnSwipe = YES;
You can hide your navigation bar by
[self.navController setNavigationBarHidden:YES];
// Hide it in the AppDelegate where you make your root view controller if using xib.
To hide toolbar with tap then you have to maintain a bool for it
if(!tap){
hideNav = NO;
tap = 1;
} else {
hideNav = YES;
tap = 0;
}
[self.navigationController setToolbarHidden:hideNav animated:YES];
OR simply use
[self.navigationController setToolbarHidden:YES animated:YES];
I want to disable navigation bar animation when page change.,
root viewController
- (BOOL)prefersStatusBarHidden{
return YES;
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];,
}
pushed viewController
- (BOOL)prefersStatusBarHidden{
return NO;
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];,
}
If both pages statusBarHidden is equal to NO or YES this method work but when i disable one of them a problem occurs. I could not upload image because of my reputation very low please check link for image.
https://www.facebook.com/photo.php?fbid=154038544933435&set=a.154038594933430.1073741827.100009818700445&type=1&theater
you should used this it work for me on tab gesture
NSTimer *timer;
if([UIApplication sharedApplication].statusBarHidden == YES)
{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
timer= [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:#selector(hideStatusbar) userInfo:nil repeats:NO];
}
calling methods
-(void)hideStatusbar
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
Implementing prefersStatusBarHidden should do the trick. No need to override viewWillAppear:animated, because iOS animates automatically from one status bar state to the next.
Be sure to set "View controller-based status bar appearance" in your Info.plist to YES.
As far as the navigation bar is concerned. If you use storyboards and use Segueues you can transition from one Navigation Controller to the another. If navigation Controller A has a visible Navigation Bar and Navigation Controller B has a hidden Navigation Bar, iOS will automatically animate the Navigation Bar away for you.
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];
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];
In iOS 6, I was using the following code to push a UIImagePickerController, of source type UIImagePickerControllerSourceTypeCamera, and to show its navigation bar. I wanted to show the navigation bar because after taking the image, I'm pushing another VC that allows the user to set some attributes in the database.
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
cameraController = [[UIImagePickerController alloc] init];
cameraController.delegate = self;
cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:cameraController animated:YES completion:NULL];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
cameraController.topViewController.title = #"Add";
cameraController.navigationBar.translucent = NO;
cameraController.navigationBar.barStyle = UIBarStyleDefault;
[cameraController setNavigationBarHidden:NO animated:NO];
}
In iOS 7 this code no longer shows the navigation bar. Does anyone know if there's a way to to get the navigation bar back for UIImagePickerController, of source type UIImagePickerControllerSourceTypeCamera?
Guess what? When imagePicker presents, it's automatic set to hidden....
All you need to do is setHidden:NO in next runloop. Like:
[self presentModalViewController:imagePicker animated:YES];
[self performSelector:#selector(showNavigationBar:) withObject:imagePicker afterDelay:0];
- (void)showNavigationBar:(UIImagePickerController*)imagePicker {
[imagePicker setNavigationBarHidden:NO];
}
#LeverkusenFan's solution works well. But instead of using a hack such as a run loop, you use the completion handler of presentViewController to achieve that effect.
[self presentViewController:cameraController animated:YES completion:^{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
cameraController.topViewController.title = #"Add";
cameraController.navigationBar.translucent = NO;
cameraController.navigationBar.barStyle = UIBarStyleDefault;
[cameraController setNavigationBarHidden:NO animated:NO];
}];
In fact a better solution that avoids the weird animation when the navigation bar shows up and which works well when you press the back button on the nav bar is as follows:
In the delegate for the UIImagePickerController implement the following function.
- (void) navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (navigationController == self.cameraController && navigationController.viewControllers.count == 1) {
// When showing the ImagePicker update the status bar and nav bar properties.
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
navigationController.topViewController.title = self.cameraTitle;
navigationController.navigationBar.translucent = NO;
navigationController.navigationBar.barStyle = UIBarStyleDefault;
[navigationController setNavigationBarHidden:NO animated:animated];
}
}
This function will get called when the ImagePicker is shown and we only make the changes for the rootViewController of the ImagePicker (i.e. the camera screen).