I’m trying to dynamically access an iOSLayoutContraint by name, but no luck:
Dim c As iOSLayoutConstraint = Container11.Constraint("Width")
c is always nil, even though I’ve named my constraint:
Further complicating matters to solve this is the function:
MobileContainer.Constraint(name as String) as iOSLayoutConstraint
This method has a tool tip and compiles without issue, but it’s missing from the documentation.
Any tips on accessing constraints would be welcomed.
Found something: It looks like the width constraint lives in the window?
Dim c As iOSLayoutConstraint = Self.Constraint("MyWidth")
Calling this from a window method returns the constraint, but it’s not where I would expect it. If I were creating this type of constraint and manually attaching it to my container control, it would be a part of the container control, not the window.
(And the docs are still missing for this function, AFAIK)
Constraints affecting the position and size of an element always live on the parent control because they can affect other controls and the layout resolver needs access to them all to solve the equation.
Width and height constraints in interface builder are a part of the control.
If this constraint were created programmatically, in XOJO or Obj-C/Swift, there isn’t a second item. The constraint would be attached to the control itself, not its parent.
They may be displayed as part of the control, but they’re not there under the hood, and so you need to interact with them in their actual location.
May I ask why fixed Height and Width are stored in the parent? Did it have to be this way?
The knock-on effect is that when you reparent a control, the fixed height or width is lost. I’m not even able to read it correctly from the control’s height or width properties—wrong values are reported in the Opening event—I’d happily add the constraint back if I could get the values.
For instance, this MobilCanvas has it’s width and height set to 40 and 20:
But in Opening, the width and height are 100 and 100:
This is a non-issue with native iOS auto layout, so I’m wondering why. iOSLayoutConstraints seem iOS specific, so it’s not for Android compatibility? Is it because XOJO only has a flat view/control hierarchy at runtime, unlike native iOS?
See my previous comment. Where constraints are stored is an Apple decision, not Xojo.