Created
October 27, 2013 10:35
-
-
Save jacklynrose/7180211 to your computer and use it in GitHub Desktop.
This is how I managed to hack the visual format language to center a few views vertically (most other ways put them at the top and bottom, or just the top, or just the bottom). Basically what I'm doing is saying that the top margin should be less than or equal to half the portrait height minus the total height of all the views you'll be centring…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
totalCombinedViewHeight = 100 | |
Motion::Layout.new do |layout| | |
layout.view view | |
layout.subviews "state" => @state, "action" => @action | |
layout.metrics "margin" => 20, "height" => 40, "halfHeight" => ((view.bounds.size.height - totalCombinedViewHeight) / 2), "halfWidth" => ((view.bounds.size.width - 100) / 2) | |
layout.vertical "|-(<=halfHeight)-[state]-margin-[action]-(>=halfWidth)-|" | |
layout.horizontal "|-margin-[state]-margin-|" | |
layout.horizontal "|-margin-[action]-margin-|" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment