Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portrait and Landscape Layouts #61

Open
IainS1986 opened this issue Apr 20, 2020 · 1 comment
Open

Portrait and Landscape Layouts #61

IainS1986 opened this issue Apr 20, 2020 · 1 comment

Comments

@IainS1986
Copy link

Hi, this isn't an issue, more a query and thought this might be the best place to ask.

I'm not really referring to Adaptive layouts, but if adaptive layouts are possible with FluentLayout then is there an example somewhere?

I'm more thinking, is it possible to setup a bunch of contraints for Landscape and a bunch for Portrait and switch between the two on orientation changes? Or is there another way to handle different layout setups for Landscape and Portrait using FluentLayout?

If I have to go the route of AdaptiveLayouts in a xib then fair enough, just trying to avoid and do everything in code with FluentLayout!

@IainS1986
Copy link
Author

IainS1986 commented Apr 20, 2020

In answer to my own question (should have just tried my hunch) and for others coming here.

The route i've taken that appears to work fine visually, is to build 2 lists of constraints, one for landscape and one for portrait.

When the view loads, I check the current orientaiton of the device and apply the relevant list, and then store off which one I applied (landscape or portrait).

Then I do something along the lines of,

`
public override void ViewWillTransitionToSize(CGSize toSize, IUIViewControllerTransitionCoordinator coordinator)
{
base.ViewWillTransitionToSize(toSize, coordinator);

var currentOrientation = UIDevice.CurrentDevice.Orientation;
if (currentOrientation.IsLandscape() && _inPortraitMode == true)
{
    _inPortraitMode = false;
    View.RemoveConstraints(_portrait);
    View.AddConstraints(_landscape);
}
else if (currentOrientation.IsPortrait() && _inPortraitMode == false)
{
    _inPortraitMode = true;
    View.RemoveConstraints(_landscape);
    View.AddConstraints(_portrait);
}

}
`

Seems to work really nice visually, not sure on how expensive it would be to remove all constraints and add back in, especially if there's like 50+ constraints?

Maybe I should load all of them in and then set Active to true/false instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant