Navigation bar and UIScrollView - ios

I've seen that with iOS7 when using a UIScrollView and a navigation controller the scroll view has to be all the way at the top of the view. Or the label or image will not be in the right spot when the app is run as seen in this question iOS 7 Navigation Bar and Scroll View are different in storyboard and simulator.
I am wondering is there a way around this. I am setting my scrollView like this:
viewController.h
#property(nonatomic,weak) IBOutlet UIScrollView *scrollview;
viewController.m
- (void)viewDidLayoutSubviews {
[scrollview setContentSize:CGSizeMake(0, 1000)];
}
My question is is there a way around this using ios7 and auto layout? Or do I just have to live with it looking weird in the storyboard?
Thanks in advance for the help.

In the Attributes Inspector, under Simulated Metrics, you can change Top Bar to None. This will simulate your view controller having no navigation bar while viewing in Storyboard. When the application is actually ran, the navigation bar will appear.

Related

UIToolbar as inputAccessoryView hides labels during push/pop animation

I have a UIViewController inside a UINavigationController. The UIViewController class overrides -(BOOL)canBecomeFirstResponder and -(UIView *)inputAccessoryView, such that it has a UIToolbar docked at the bottom. This UIToolbar has a UILabel as a subview. I should mention that both are fully wired up programmatically using auto layout. Now when the view controller is pushed onto the navigation stack, the label is not visible during the push animation. Only after the push animation has finished, the label suddenly appears on the tool bar docked at the bottom. The exact same thing happens when the navigation stack pops back to this view controller. What could be causing this behavior?
Are you programmatically creating your constraints? I had a similar issue where the UILabel wasn't appearing at all, and I switched my constraints to use the Visual Format Language and it magically worked.

hidesBarsOnSwipe doesn't work

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.

Programmatically add UISegmentedControl in UIToolbar below UINavigationBar

I'm trying to get this to work on iOS 7 and 8+.
In loadView of the viewController, I add a UISegmentedControl, along with flexible spaces, as items to a UIToolBar. I then add the UIToolbar as a subview to the main view, setting the vertical position to be the height of the navigation bar.
First problem. The UISegmentedControl is vertically off center so the top of it, is cut off.
Second problem. Rotating to landscape messes it all up. Specifcally, the UIToolbar seems to move underneath the navigation bar whereas the UISegmentedControl doesn't.
Autoresizing issue? I've tried various settings and can't seem to get it to center vertically within the UIToolbar.
It could be that your UIToolbar constraints are not set properly and also that there is no flexible space around the segmented control. Here's a link to a storyboard file I made that have proper constraints and flexible space, tested to work.
Preview:
Here's the Storyboard file: http://www.filedropper.com/main_4

UIViewController auto layout in iOS8

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.

UITableView in AutoLayed Out Xib Crops in 3.5-Inch screen

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

Resources