AutoLayout: when to use bottomLayoutGuide vs. “V:[continueButton(50)]|”
I'm having a UIViewController inside a UIPageViewController, where I would like to add a button at the very bottom. I just don't understand the difference between NSLayoutConstraint.constraintsWithVisualFormat("V:[button]|", options: .DirectionLeadingToTrailing, metrics: nil, views: ["button":button]) // works and NSLayoutConstraint.constraintsWithVisualFormat("V:[button][bottomLayoutGuide]", options: .DirectionLeadingToTrailing, metrics: nil, views: ["button":button, "bottomLayoutGuide":bottomLayoutGuide]) // doesn't work The first line adds the buttom at the very bottom, with the second line there is a padding of 50px between the button and the bottom. Does this have to do with the UIPageViewController (which itself is in a UINavigationController)?
The bottom layout guide is useful for layouts where the parent controller has some kind of view that overlays the current view controller's contents. So in your case the UIPageViewController has such a view, which is a UIPageControl view that you may not want to be overlapped, thus if you specify the bottom layout guide as a boundary, your view will pin right above the UIPageControl. That's convenient especially if you depend on such a constraint (that becomes clear in the example I provide below). A UITabBarController also has a bottom layout guide, which is the tab bar's top. This is convenient because most of the times you'll need a constraint to the top of the tab bar otherwise views will be situated underneath it (which may lead to bad user experience [think: If you constrain a tableView to the very bottom (NOT the bottom layout guide) then the last cell may be overlaid by the tab bar, which is certainly bad UX]). So as you can see sometimes it is useful to have the ability to constrain to the bottom layout guide of a view controller where the parent controller's elements occupy space that may not be necessarily good to place a view under. Same goes for UINavigationController, if you have a view controller contained in a UINavigationController, the topLayoutGuide will basically indicate where the UINavigationControllers navigation bar ends, thus it would be useful to constrain any views to that top layout guide otherwise the views will end up underneath the navigation bar. In your case I think you'll be fine constraining your views to the very bottom of the UIPageController's view as views underneath a UIPageControl usually contain images which will not look obfuscated by the UIPageControl (The page control serves more as a visual feedback mechanism than an interaction element). As matt pointed out in his comment by doing something like V:[button]|, you are basically constraining the view to the very bottom of its superview, NOT the bottom layout guide (which is the UIPageControl in your case). On the contrary, V:[button][bottomLayoutGuide] will constrain the view to the UIPageController's UIPageControl, which probably has a default size of 50, which is why there is a difference between those two. I hope that made things clear.
Is there any way to keep another app from displaying picture in picture?
How do you select/highlight a part of the chart through code? (Charts- PieChartView)
Core Location iOS Plugin for Unity3D
the appearance of cells with animation resize picture [duplicate]
view hierarchy error - trying to open up a new view controller in a new storyboard
What would be a good approach for developing front-end for ios apps? [closed]
How to use GPUImageLookupFilter
calculate region without MKCoordinateRegionMakeWithDistance
Add Airplay Icon to AVPlayer
How to scroll up an entire table view in Swift?
Is it possible to export a Balsamiq mockup to Xcode?
Connect to Node.js Express from iPad [closed]
Resize CAShapeLayer in Swift
App closes when iPhone screen is locked
How to make UICollectionview cell height dynamic?
Logging a user out with Firebase 3 and Swift still shows the `currentUser`