iOS - Top Layout Guide height issues - ios

I am refactoring some views in my application regarding iPhone X constraints and moved a group of views into a TabBarController view with also a Navigation views. Everything working just fine but one thing. Well... There is always that "one issue left" thing, isn't?
So the issue that I have is that the Top Layout Guide is set high. And I don't want that. See screenshot about this issue.
I have set the top constraint of the labels "Maandag" and "Op afspraak" (top one) to 0. Well to the Top Layout Guide. All views that I converted to this TabBar view has this issue :( I am using Storyboards.
This is the result on device (same on all kind of devices)
Thanks in advance!

With iOS 11, Apple is deprecating top(bottom)LayoutGuide and switching to the safeAreaLayoutGuide. In code, you could pin your view using view.safeAreaLayoutGuide.topAnchor, but in storyboards you'll want to pin stuff to the safe area node inside your view controller's view:

Related

Safe areas on iPhone X wrong

I have a pretty complex app, that causes the safe areas on an iPhone X to be wrong (pushed down).
This screenshot is from a storyboard. It's a container view aligned to the bottom anchor of the Safe Area Layout Guide.
Everything looks fine there and produces the correct result in an empty, new project.
But as soon as I instantiate and push the view controller in the original app, the result is this:
What could cause the safe areas to be distorted?
The property additionalSafeAreaInsets is definitely not set anywhere in the app. I've played around with a couple of other UIViewController properties, but nothing seems to change this.
Thanks!
Please share constraint layout view for your button to get proper/exact solution to your problem.
Here I had same problem.
I had added another view as a subview (gray view) in a main view and moved my button in it. I enabled the safe area layout guide for both main view and gray view.
Safe area layout for gray view safes my button inside safe area.
iPhone X, Layout Preview:
Hope this may help you!
Click on the View(which contains your button) and then check Safe Area Layout Guide
So to perfectly answer my original question:
What could cause the safe areas to be distorted?
Turns out a totally different part of the app was modifying the size of the parent view controller's view.

UITableView leaving gap below transparent UINavigationBar (within single UIView on UIViewController)

I am working on a Swift iOS8/9 project and using Xcode 7, with storyboard / autolayout, etc. (For completeness: I started at the beginning on the year on older versions of Xcode, etc.)
I have a a UINavigationController hierarchy and some View Controllers contain a single UIView which contain a single child, a UITableView. (I am choosing not to use UITableViewController, so suffice to say ... it is not an option.)
The problem: The tableview starts 64 pixels (status plus nav height) too low:
Now: I've had things working for some of my UIViewControllers containing a UICollectionView within a UIView but I achieved it (after lots of poking / prodding, and a while back) by a top alignment constraint from the top of the UICollectionView to the top of the Top Layout Guide. (Looking through my storyboard I some alignments and some vertical distances, but all to top of Top Layout Guide.)
I am looking for help understanding if I can do what I want, if the approach of constraining the top of the tableview to the top of the layout guide is correct, or if there is a better way.
Unfortunately, I cannot seem to repeat this (perhaps 'cos I've forgotten some key press combination jujitsu, or new Xcode, or collection != table, or something in my view hierarchy. (I've checked all segues are adaptive push, I've even deleted/re-built this VC since I had one model segue, just in case it was confused that this VC isn't in a navigation view controller hierarchy.)
If I control/drag to connect or select the two to align:
this is what I am offered - note no "align to top":
Note: Here are the table settings that (to my understanding) should be adjusting edge inset and scroll offsets correctly, and do appear to ('cos it is the only child of the top view, per documentation.)
Here are the frames after view did layout subviews:
The approach that I ended up using came to me when I spoke to #ProgrammingBonn and mentioned the frames. I saw that the primary UIView was position as I wanted, and so it (finally) dawned on me to align the top of UITableView to the top of the UIView.
(I suspect that much as I was building my own ViewController and not relying upon UITableViewController I had an over inflated view of this particular view within the hierarchy. It was a subview not a primary view, despite occupying all the screen real-estate.)
So, to be clear:
I selected the UITableView, then command/selected the UIView (the main one, and it's parent) and then used the "align" tool to top align those two.
Try unchecking the "Adjust Scroll View Insets" option.
I am not sure whether this will fix your problem but have you tried playing around with viewController.edgesForExtendedLayout?
See more info here:
Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout in iOS7

Google AdMob Test Banner Not Showing

I'm having trouble displaying the Google AdMob test banner. I created a simple application as described in their docs https://developers.google.com/mobile-ads-sdk/docs/admob/ios/quick-start#manually_using_the_sdk_download. The only difference from that sample is that I'm using a UINavigationController
After looking around for a solution to another issue I found that by adding [self setEdgesForExtendedLayout:UIRectEdgeNone]; on my ViewController the banner appeared!
Has anyone run into this? What workarounds/fixes are there? Am I doing something wrong?
UPDATE 1
I created a sample project so you can see and test. I created Tags along the way to make it easy for you to navigate backwards as I made my changes. https://github.com/RoLYroLLs/GoogleAdMobTest.
One important thing to note is that as I made my changes, the ad doesn't appear when the label AND the textview were removed from the view (check tag v0.1.3. When I removed either one the ad did show up (check tags: v0.1.1 and v0.1.2).
In tag v0.1.5 I added [self setEdgesForExtendedLayout:UIRectEdgeNone] to make it work, but I don't like what it does to the tab bar and the navigation bar, they look darker or something.
Any feedback is welcome. Thanks!
UPDATE 2
The issue seems to be fixed when using Xcode 6.0.1. I guess it was a bug in Xcode 5.x.x?
You have to setup the proper auto layout constraints so when the view shifts behind the navigation bar, the banner adjusts itself.
The banner should have the following constraints:
leading space to superview
trailing space to superview
top space to top layout guide
The tableView should have the following constraints
vertical spacing to admob banner
leading space to superview
trailing space to superview
bottom space to bottom layout guide
You can set the constraints visually in the storyboard.
This looks like it was a bug in Xcode 5.x.x as I just upgraded to Xcode 6.0.1 and it works just fine.

UIScrollView in NavigationController ignores top layout guide

I've seen similar questions about custom transitions(iOS7 Custom ViewController transition and Top Layout Guide and Navigation controller top layout guide not honored with custom transition), but I have problem even with regular push. I'm using latest Xcode available now (Version 5.1.1 (5B1008)).
Here is my storyboard:
Problem occurs in 3rd VC
Here is 3rd VC settings:
My 3rd controller's layout is follows:
UIView
UIScrollView
InnerUIView
Other views
I've tried two different ways to create a layout:
Ignore top layout guide (it has y = 64 because of nav bar)
I pinned scrollview's top to container (ignoring topLayoutGuide), manually set height of inner view and pinned its top to scrollView. It gave me the following result:
Looks fine, but why do I need top layout guide then?
Use topLayout guide
ScrollView's top is pinned to topLayoutGuide.
As you can see, top button moved down and view looks strange.
What is the right way of creating such layouts?
I had the same problem and spent hours pulling my hair out.
My container view inside scrollview had weird top offset despite the fact that it had top constraint set.
The workaround I've found - you have to uncheck Adjust Scroll View Insets in your controller layout options
that way content view (in my case) stays pinned to scrollview's top.
Unfortunately I couldn't find any reasonable explanation of this behaviour.
In my case, Xcode 7 and 8, I had to uncheck the 'Adjust Scroll View Insets' for the Views in my Navigation View Controller. And yes, it wasted too much time before I figured this out.
EDIT: Apple has found out that we have found a solution, so they managed to break this again in XCode 9 and 10, to keep us developers pulling our hair. Haven't found a solution yet.

scroll views working fine in iOS 7 with problems in iOS6

I hate iOS scroll views with auto layout, they are driving me crazy!:-D
I have found a method which works perfectly on iOS 7 to use scroll views:
I put the scroll view directly in the main view, attaching the scroll view to the edges of the super view(top,bottom leading and trailing space equals to 0).
Then I put a UIView into the scroll view attached to the edges of the scroll view, (top,bottom leading and trailing space equals to 0).
Then I set the height constraint of the most internal view, I link it at my ViewController class, and I modify its value programmatically.
Or, if the view it's 'static' I put every component using the storyboard into the internal UIView, starting with the one at the Top attached to the top of the super view, the one under, attached with the constraint 'Vertical Spacing' referred to the one over him..and so on... Until the last, which is also attached to the bottom of the UIView..
Everything works fine in iOS 7, it's perfect, but iOS 6 is messing around with the constraint.
When I first launch the view everything is perfect, but it seems to recalculate the constraints even on the didappear(and in a bad way), in fact, if I leave my view while it's scrolled down, when I come back to it(let's say we are in a navigation controller) , is like it's everything 'moved up' and the components at the top are hidden.
Is there a way to make scroll views work in both iOS 6 and iOS 7, I'n thinking at two storyboards as the only solution, please tell me there is another way... :-)
thanks everyone, I post two images explaining my problem, taken from the top of the screen:
Well uncheck use AutoLayout in file inspector and try.

Resources