How to Prevent Status Bar from Overlapping Content with Hidesbarsonswipe Set on Uinavigationcontroller

How to prevent status bar from overlapping content with hidesBarsOnSwipe set on UINavigationController?

Building off of anas' answer, I have a working solution (I'm assuming tableViewController is your UITableViewController instance):

In a UINavigationController subclass (or also potentially from tableViewController):

- (void)viewDidLoad {
if ([self respondsToSelector:@selector(barHideOnSwipeGestureRecognizer)]) {
// iOS 8+
self.hidesBarsOnSwipe = YES;
[self.barHideOnSwipeGestureRecognizer addTarget:self action:@selector(swipe:)];
}
}

- (void)swipe:(UISwipeGestureRecognizer *)recognizer {
BOOL shouldHideStatusBar = self.navigationController.navigationBar.frame.origin.y < 0;
tableViewController.hideStatusBar = shouldHideStatusBar;
[UIView animateWithDuration:0.2 animations:^{
[tableViewController setNeedsStatusBarAppearanceUpdate];
}];
}

In your tableViewController:

@property(nonatomic, getter = shouldHideStatusBar) BOOL hideStatusBar;

- (BOOL)prefersStatusBarHidden {
return [self shouldHideStatusBar];
}

Let me know if this doesn't work for you. A few non-obvious things:

  • self.navigationController.navigationBar.frame.origin.y was -44 (the negative height of the navigation bar) when hidden, and 20 (the height of the status bar) when visible. There was no in-between, even during animations, so a negative value == hidden and a nonnegative value == visible.
  • The child view controller is the one queried for whether or not the status bar should be hidden. In my case, I have a UIViewController within a UINavigationController within a UITabBarController, and it didn't work until I overrode prefersStatusBarHidden on the UIViewController.
  • Since a hidden status bar has no frame, your content might jerk upwards 20 points unless you wrap the call to setNeedsStatusBarAppearanceUpdate in an animation block.
  • Hopefully the syntax is correct; I backported this from my Swift code.

How to stop an uitableview housed in tabbarcontrol from overlapping the status bar?

Do you use Storyboards and autolauyout?

If so, just:

  1. Select the ViewController in storyboard

  2. select attribute inspector

  3. Status Bar default

  4. Select The tableView and set the top constraint to top Layout guide

If its not working this way plan B would be to use a normal ViewController, add a container to it, embed your TableViewController into the container and do the above stuff on the ViewController.

Swift iOS -NavigationBar hidesBarsOnSwipe never reappears when setting CollectionView Frame under Status Bar

It was a simple fix. I followed this answer.

override var prefersStatusBarHidden: Bool {
return navigationController?.isNavigationBarHidden ?? false
}

And be sure you have "View controller-based status bar appearance" = "YES" in your application .plist file.

Hide status bar whenever nav bar is hidden - SWIFT iOS8

Sorry if this answer is a little late, but here is one way to do it.

Use the prefersStatusBarHidden() method within your view controller.

override func prefersStatusBarHidden() -> Bool {
if self.navigationController?.navigationBarHidden == true {
return true
} else {
return false
}
}

Basically says that when the Nav bar is hidden, then the status bar is too and vice versa.

Hide navigation bar when scrolling without hiding the status bar and its background

please add this method

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
[[self navigationController] setNavigationBarHidden:YES animated:YES];

}

in swift

func scrollViewWillBeginDecelerating(scrollView: UIScrollView) 
{
}

iOS TableViewController Scrolling away content and navigation bar under status bar

When creating this kind of structure (table + other elements), the best approach is to actually have a ViewController that contains a TableView and additional elements (like your navigation). Do not try to put elements, that are not part of the table itself inside the table.

Here is an example of the structure, where I have intentionally coloured the custom view (in your case the navigation) orange. As you can see, it is outside the table. This way the showing and scrolling of the table is completely separated from the other elements.
Sample Image



Related Topics



Leave a reply



Submit