I recently updated my XCode 6.3 to 7 and strange things started to happen with my auto layout constraints in the storyboard.
My app uses UITabBarController with three tabs. The initial tab has a UICollectionView with top constraint set to 44px from the top layout guide (there is a toolbar in the embedding UINavigationController.
When I run the app on iOS 7.1 (iPhone 4), everything looks fine. The collection view doesn't go bellow the toolbar. However in iOS 8.4 (iPhone 6) the collection view goes bellow the toolbar UNLESS I switch tabs and go back to the first one, where the collection view is positioned where it should be.
What I did:
Unchecked all "Extend edges under...." for every view controller in the chain
Set all simulated metrics for Status/Top/Bottom bars to "None" in every view controller in the chain
I had the idea to check for #available(iOS 8.0, *) and extend the constraint constant +20 pixels. But when I switch back to this tab, the collection view goes 20 pixels lower than where it should be.
So, I guess something happens to the view controllers when I switch tabs. What is it? Or is there any solution. I'm on a deadline and this is the only problem I have with my app.
p.s. I can provide source code and XCode screen shots if needed. But still, I think it's something more theoretical, than practical.
1) click on your UITabBarController in storyboard->identity inspector
2) uncheck "Adjust Scroll View Insets"
repeat for individual view controllers inside UITabBarController
Sometimes this happen also to me. I suggest replacing the top layout constraint with an height constraint equal to the view of the ViewController, this resolved my problem.
Related
I have a UIViewController that contains a UISegmentControl at the top, and a UITableView below. The layout is very simple. The UISegmentControl Top Margin is 16pts from the Top Layout Guide. The tableView is relative to the UISegmentControl. The view is part of a UITabBarController set. The UITabBarController is the storyboard's initial view controller.
I'm experiencing a problem where, on iOS 9 and 10, the UISegmentControl and the UITableView are positioned too high at initial app launch. As a result the UISegmentControl is partially obscured. If I switch to another tab or the next view in the hierarchy (by tapping a table cell), then go back to this view, the problem resolves itself.
The problem does not occur on iOS 11. The app doesn't support anything earlier than iOS 9.
Here are screenshots, taken both immediate after launch and then after switching to another tab then back again. Any suggestions appreciated.
Turn off extend edges under top bar :
Check your view controller attributes inspector in IB. Look for
"Extend Edges" option under View Controller, and uncheck "Under Top
Bars" if it is checked.
I have a problem with a "double" navigation bar in a screen of my iPhone app.
Starting position:
Xcode 8, Swift
I have a TableView with static lines that is embedded in a navigation controller. From the first cell I then call a screen (Segue Show Detail), which is very complex (labels, text boxes, buttons, etc.). When I execute the "Reset to suggested constraints" function on the screen, the screen is supplied with "generated" constraints. This is still clear. When I run my app in the simulator (iPhone 6) or my own iPhone 6, I see on the above screen a status bar, then my right navigation bar (Back button, title) and below an "empty" 2.Navigation bar. This decreases the screen down and is no longer fully visible. If I delete the constraints for the screen with the "Clear Constraints" function, the screen in the simulator (i6) looks good as I develop in the storyboard for the iPhone 7. But when I connect my own iPhone 6 and test, the screen does not fit completely to my iPhone, because right and down is something truncated.
I suspect the error in the "generated" constraints.
Now my question:
How can I check the generated Contraints (well over 100) for errors?
In the Internet and the forum I found nothing, which could help me.
Workaround for me:
The top UI element on the screen is a label across the entire width of the screen. For this label, I set a constraint manually, in addition to the generated constraints
Label.top = Top Layout Guide.bottom + 44,
whose value I then change to the value
Label.top = Top Layout Guide.bottom
This causes the label to slide directly below the status bar in the storyboard. The navigation bar is then no longer visible in the storyboard. This makes the placement of UI-Elements at the bottom of the screen somewhat more difficult because you do not know exactly which space is still available.
The display in the simulator (i6) and on my iPhone 6 looks however through the workaround ok.
For your help I would be very grateful.
Greeting Reinhard
in my universal app I have an UITableViewController embedded in a UINavigationController. When I add a UIView to the top of the tableView and insert a UILabel which is centered in the container, the label is only visible on iPhone but not on iPad.
I tried creating a new testapp, only consisting of these two controllers, the view and the label. It works on both, iPhone and iPad. So I added two new controllers to my app in the same way and made the navigation controller the initial view controller. Label is visible on iPhone but not on iPad.
For me it seems, that I have changed some global settings in the app; on another view I have similar problems with stackViews, but I first concentrate on this "simple" problem...
Any ideas what might be wrong in my app-settings?
tableViewController embedded in navigationController
Take a UIViewController embedded in a UINavigationController. Add View, Label, and TableView and check it
Ok. Now I know what was the problem. Never have checked, what's going on with those size classes.
During development I changed from any/any to a smaller size, not knowing, that this is not only taking effect on the layout in the storyboard. Everything I added after changing did'nt show on iPad.
Solution: Select storyboard, in "File Inspector", uncheck "Use Size Classes"
Using XCode 5, downloaded today. iOS 7. When I run app the table view header appears underneath the navigation bar, I don't mind it scrolling underneath the navbar but I'd like for it to appear unobstructed initially. I am trying to figure out how to use the topLayoutGuide mentioned in the iOS 7 transition guide, which says you can set a constraint relative to it, but doesn't explain how.
Anyone know?
Transition guide here:
http://tinyurl.com/mgdl4sg
Just realized that my storyboard was still set to XCode 4.6
You have to go to the File Inspector (icon that looks like a file icon in the right navigation panel in Xcode) and then under "Interface Builder Document" where it says "Opens in" change to Default (5.0) and / or "View as" iOS 7.0 and Later
Then your IB document will show the guides inside the left hand navigation panel under the view controller
Often if you select the view, and click the "Pin" button at the bottom right, pin the vertical spacing, and the dropdown will have an option to use the topLayoutGuide
In my Storyboard, was still have trouble getting my UITableView to pin the vertical spacing between the top of the table view and the top layout guide. Every time I control-dragged I would get it pinning to the bottom of the table view instead of the bottom. But then I tried manually dragging the table view so that it appeared below the nav bar in IB and then control-dragged and the vertical spacing finally worked.
I had the same problem, and in Storyboard when I set the top bar to Opaque the top of the scrollView changed so that it wasn't obscured by the nav bar. Makes sense, but it's unfortunate that you can't use a translucent nav bar and get the same effect.
In my iPad app, the view controller include three button, one navigation bar and one tool bar.
When i rotate my view controller from portrait to landscape mode, three buttons are disorder.
The navigation bar also collapse to tool bar.
How can i do it?
You need to learn about layout. You can lay out subviews of your view in three ways:
Manually
Autoresizing (springs and struts)
Autolayout (constraints)
If this is a new project in Xcode 4.5 or later, you are using autolayout by default. So you need to go back into the nib and edit the constraints that Xcode already gave you, because obviously they are not what you want.
You might want to read the Layout section of my book, which has extensive discussion of how autolayout works and how to edit constraints in the nib: http://www.apeth.com/iOSBook/ch14.html#_layout
Ideally you should keep your content under one xib per view controller, linking your buttons and nav bars by pinning to your layout should rotate properly; however there is one other option for a viewing a different xib when the device is rotated, see the answer below.
Easiest way to support multiple orientations? How do I load a custom NIB when the application is in Landscape?