FluentLayout / Cirrious.FluentLayout

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

TopLayoutGuide #45

Closed yaliashkevich closed 5 years ago

yaliashkevich commented 7 years ago

Is it possible to setup following constraint in terms of fluent layout:

View.AddConstraint(NSLayoutConstraint.Create(table, NSLayoutAttribute.Top, NSLayoutRelation.Equal, TopLayoutGuide, NSLayoutAttribute.Bottom, 1f, 0f))

? TopLayoutGuide is of type IUILayoutSupport.

Cheesebaron commented 7 years ago

TopLayoutGuide has a Height property, why don't you use that?

yaliashkevich commented 7 years ago

I have following working: subview.Top().EqualTo().BottomOf(ObjCRuntime.Runtime.GetNSObject(TopLayoutGuide.Handle))

But Length looks better, thanks.

The only thing that using Length changes semantic: in fact that means using a constant instead of pinning top of the view to bottom of other object , which position can be changed in theory during view lifecycle: i.e. portrait/landscape mode without status bar.

yaliashkevich commented 7 years ago

I've just checked TopLayoutGuide.Length property but value is zero. So it does not help in following setup:

public override void ViewDidLoad()
{
    base.ViewDidLoad();

    var child = new UIView()

    View.AddSubview(child);
    View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
    //View.AddConstraint(NSLayoutConstraint.Create(child, NSLayoutAttribute.Top, NSLayoutRelation.Equal, TopLayoutGuide, NSLayoutAttribute.Bottom, 1f, 0f));
    View.AddConstraints(
        //child.Top().EqualTo().BottomOf(ObjCRuntime.Runtime.GetNSObject(TopLayoutGuide.Handle)),

        // here TopLayoutGuide.Length == 0, so it doesn't work
        child.AtTopOf(View, TopLayoutGuide.Length),
        child.AtLeftOf(View),
        child.AtRightOf(View),
        child.AtBottomOf(View)
    );
}

        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);
            // here TopLayoutGuide.Length == 20, as expected view is already displayed
            Console.WriteLine("Length: {0}", TopLayoutGuide.Length);
        }
nilsmelkerud commented 6 years ago

According to https://developer.apple.com/documentation/uikit/uiviewcontroller/1621367-toplayoutguide you should query this property (TopLayoutGuide.Length) within your implementation of the viewDidLayoutSubviews() method.

gshackles commented 5 years ago

Closing since it seems like this was sorted, please feel free to reopen if not!