FluentLayout / Cirrious.FluentLayout

FluentLayout for Xamarin.iOS - sample uses MvvmCross
Microsoft Public License
148 stars 54 forks source link

Portrait and Landscape Layouts #61

Open IainS1986 opened 4 years ago

IainS1986 commented 4 years ago

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 commented 4 years ago

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?