Have a following structure:
UIViewController (VC) with some UIViews(views) on the top half of screen and UITableView (tableView) on the bottom half of screen. All are on the same hierarchy level within VC's view.
VC is managed by UINavigationController.
Auto-layout is off. Using autoresizing masks.
dataSource and delegate methods are set up and works fine.
What I want to realize:
Hide a navigation bar when scroll up and show in after the scroll down.
What I did:
Since my project supports iOS8+ only, just setting:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.navigationController.hidesBarsOnSwipe = YES;
}
should be fine.
What I have:
Swiping up and down on the views hides and shows navigation bar respectively.
Scrolling tableView makes no sense.
Spent some time on that and found that resizing tableView to make it match to vc's view solves the problem.
Edit:
Is it mentioned somewhere in the docs that table view should be only full screen?
Found interesting thing: even if you didn't set hidesBarsOnTap to YES and try to tap on navigation area (i.e. when it's still hidden after swipe) - navigation bar will show after that. Very annoying if you have any UI elements in that area.
Related
After updating device to iOS 8 the next issues with layout occur.
I have an UITabBarController which contains two UITableViewController embedded in UINavigationController. This is main view.
Also there are several UIViewControllers designed in StoryBoard (not embedded in UINavigationViewControllers). These are secondary views. All of them have "Hide Bottom bar on Push" set to YES. Constraints are set to determine layout.
All secondary views are shown with:
UIStoryboard* sb = [UIStoryboard storyboardWithName:STORYBOARD_NAME bundle:nil];
UIViewController* secondaryView = [sb instantiateViewControllerWithIdentifier:_name];
[navigationController pushViewController:secondaryView animated:YES];
All works fine on iOS7.
But with iOS8 there are some problems when secondary view controller appears:
All pinned to bottom UIViews are shown on wrong places for a moment and then "jump" to correct place. Looks like first position is calculated including bottom bar (which is hidden due to "Hide on Push")
If there is UITableView as subview: top pinned subviews again are show on wrong place for a moment and then "jump" to correct place. Looks like first position is calculated not including navigation bar size. If i remove UITableView from controller - all works fine (except p.1)
Tried to set Simulated metrics for secondary views - did not help.
These "jumps" are really annoying. Would appreciate for any advices.
I had a similar problem with jumping when hiding the tab bar from the Storyboard.
Make sure your bottom subviews are pinned to the superview rather than the Bottom Layout Constraint.
You have to do this from the menu - Editor - Pin - Bottom Space to Superview, because the Auto Layout menu in Interface Builder pins to Bottom Layout Constraint by default.
As far as i experienced iOS 8 have issue in tabbar controller mixed with navigation bar controller .. removing one of them will make it run ok again.
I have xib in which button and uicollectionview appears as follows:
Now, when I run it , it appears as follows:
I want to remove white space above photos. I want to show photos just below from button. I have not marked header section in xib too. But, when I scroll up, the images move upto just below buttton too.This means frame is starting from just below button, but, I am getting extra white space.
So, can anybody help me to remove extra white space?
Add this code to your Controller class
- (void)viewDidLoad
{
[super viewDidLoad];
self.automaticallyAdjustsScrollViewInsets = NO;
}
Here is doc for automaticallyAdjustsScrollViewInsets
Default value is YES, which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by the status bar, navigation bar, and toolbar or tab bar. Set to NO if you want to manage scroll view inset adjustments yourself, such as when there is more than one scroll view in the view hierarchy.
I had the same problem. What work for me was to set automaticallyAdjustsScrollViewInsets = NO not only on the ViewController containing the CollectionView but on its parent ViewController too, because the child ViewController was in a ContainerView.
It can be done in the Interface builder too:
Auto adjust scroll view insets
I have a UITabBarController which has four tabs. One of those tabs opens a my results screen (a UITableViewController).
On showing this screen, I want to move the UINavigationBar down 20px (to make room for a custom UIStatusBar which I show on all screens).
On all my other screens, I add some code to the viewWillAppear method to change the self.navigationController.navigationBar.frame.origin.y to 20.
but these are all "non-root" screens (i.e. a pushed view with a back button).
However on THIS screen the UINavigationBar must be initially visible, even though it is the root view. I use the same code, but it doesn't move the view down.
I'm assuming autolayout is moving it back into position, so I tried adding this code into viewWillLayoutSubviews and viewDidLayoutSubviews. But when I do this the navigationbar doesn't move down until the first time the tableview is scrolled.
What do I need to do to force the navigationBar to move down (and stay down) before the screen appears?
Are you using storyboards? Set the Y in storyboards to 20, Make your viewcontroller implement UINavigation bar, then add this code:
-(UIBarPosition)positionForBar:(id<UIBarPositioning>)bar{
return UIBarPositionTopAttached;
}
This will tell the app that the navigation bar is to be attached, it will remain at 20px but extend the background all the way up.. So essentially it'll look like it's at y = 20.
I have an app that uses navigation controllers and a tab bar controller. So my view controllers all have navigation bars and tab bars.
When I add a UITableView to a UIViewController, then run the simulator for a 3.5-inch screen, the following happens
The top of the table doesn't start at the of the UIViewController (right underneath the navigation bar)
The bottom content (if I had more than one page and scrolled to the bottom) gets cut of
If I use a style == Grouped, then the top header always gets cut off
To see what I mean, try these steps:
Create a new file of type UIViewController with a xib
Make sure AutoLayout is checked
In interface designer, set simulated metrics to have a translucent top bar and a bottom tab bar.
Add a UITableView to the cell
Add some data in it so you can see the data and scroll
Run the app
Can anyone help provide guidance as to how to fix these issues? Are y'all getting these problems too or is it just me?
Assuming it reproduces on iOS 7 place that in your's view did load:
- (void)viewDidLoad {
[super viewDidLoad];
// To support iOS 6
if ([self respondsToSelector:#selector(setEdgesForExtendedLayout:)]) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
}
I have a UINavigationController with standard UINavigationBar. When presenting certain UIViewControllers and orientations, the UINavigationBar may or may not appear and it may or may not have a prompt element. This means that the bar height changes frequently.
I have some subviews below the UINavigationBar set with NSLayoutConstraints to topLayoutGuide. It generally lays out as expected, adjusting vertical position of the subviews appropriately based on the height of the UINavigationBar. What it does not do is move the subviews at times when the UINavigationBar is animated after the view is already displayed.
Specifically, coming from a state with UINavigationBar hidden, transition to a UIViewController which does not hide the navigation bar to one which does. The view displays, then navigation bar animates into place. The subviews do not move down. If I rotate the device, every things lays out appropriately again. Only when animating the navigation bar in and out or to display/hide the prompt I not find a hook to reevaluate the constraints.
I tried [self.view updateConstraints] and [self.view updateConstraintsIfNeeded] in various places such as viewDidAppear, viewDidLayoutSubviews. Nothing seems to update that topLayoutConstraint.
I am familiar with edge restraints, translucent navigation bar and other various methods of keeping the entire view from appearing under the navigation bar. I do want to keep view full size and I want the translucent bar so these are not solutions for me. It seems the constraints should handle this automatically, hence the "auto" in auto layout.
To simplify, for recreation, UINavigationController with rootViewcontroller showing normal navigation bar with just a title. In viewDidLoad of the next presented viewController I have [self.navigationContoller setPrompt:self.myPrompt]. The view is presented, when the prompt is set, the navigation bar grows larger. Some labels below the bar are set with relation to topLayoutGuide, which places them correctly initially. I expect they would move down when the bar grows. Rotate device back and forth, they now layout correctly. Pop the viewController and push back to top, repeats as above.
So, it turns out it was all me. After trying all manner of forcing layout updates in all sorts of ways, the solution was to move the [myView setPrompt:myPrompt] out of viewDidLoad and call it in viewDidAppear instead.
Works completely as expected. Navbar grows, subviews shift and shrink as needed. Now I have to hunt down all the experimental code I plastered everywhere trying to do it wrong.