Reputation: 35050
I need this grid layout, view structure with Storyboard. Is it an easier way to set up, or I need to calculate size / 4, and multiply it by the index, and calculate the center X, Y coordinates, and adjust NSLayoutConstraint
at each rotation?
Upvotes: 2
Views: 76
Reputation: 176
The above answer is perfect but we can also handle it by using storyboard.To explain I get 3 UIView
into a stack view
with below property.
Now when I go to landscape
from portrait
mode the height of the screen is converting to compact
from regular
.So we can change stack view axis
from vertical
to horizontal
according to height change of the screen.below gif explain you visually.
for further information you can visit this link.
Upvotes: 0
Reputation: 100503
You can use UIStackView
with default vertical and change it's axis to horizontal in landscape size class , with distribution Fill-Equally
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
if UIDevice.current.orientation == .portrait
{
self.stackV.axis = .vertical
}
else
{
self.stackV.axis = .horizontal
}
}
Upvotes: 3