Closed yaliashkevich closed 5 years ago
TopLayoutGuide has a Height
property, why don't you use that?
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.
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);
}
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.
Closing since it seems like this was sorted, please feel free to reopen if not!
Is it possible to setup following constraint in terms of fluent layout:
? TopLayoutGuide is of type IUILayoutSupport.