Hi everybody! I can’t seem to get an iOSLayoutConstraint to work.
This is what works fine:
[code]Dim ctrX As New iOSLayoutConstraint(imgTest, iOSLayoutConstraint.AttributeTypes.CenterX, iOSLayoutConstraint.RelationTypes.Equal, LineField, iOSLayoutConstraint.AttributeTypes.CenterX, 0.46, 0)
ctrX.Active = True[/code]
It sets the imgTest horizontal center to 46% of the LineField horizontal center. The problem is that 0.46 is not static but needs to be calculated. So I’m adding the calculation and replace the value 0.46 with intScale. The variable intLoc is being passed to this method from outside.
[code]Dim intScale As Double
intScale = (100 - intLoc) / 10 * 0.18 + 0.1
Dim ctrX As New iOSLayoutConstraint(imgTest, iOSLayoutConstraint.AttributeTypes.CenterX, iOSLayoutConstraint.RelationTypes.Equal, _
LineField, iOSLayoutConstraint.AttributeTypes.CenterX, intScale, 0)
ctrX.Active = True[/code]
Now nothing happens. The imgTest does not move at all. I thought maybe it’s because intScale has lots of decimals. So I’m doing this:
[code]Dim intScale As Double
intScale = (100 - intLoc) / 10 * 0.18 + 0.1
Dim strTemp As Text
strTemp = intScale.ToText(Locale.Current, “0.00”)
intScale = Double.FromText(strTemp)
Dim ctrX As New iOSLayoutConstraint(imgTest, iOSLayoutConstraint.AttributeTypes.CenterX, iOSLayoutConstraint.RelationTypes.Equal, _
LineField, iOSLayoutConstraint.AttributeTypes.CenterX, intScale, 0)
ctrX.Active = True[/code]
Now I’m getting an exception when I try to create the iOSLayoutConstraint:
NSLayoutConstraint for <UIImageView: 0x116d60880; frame = (305 45.5; 57 38); clipsToBounds = YES; opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x6000002497e0>>: A multiplier of 0 or a nil second item together with a location for the first attribute creates an illegal constraint of a location equal to a constant. Location attributes must be specified in pairs."
I have no idea what I need to do. It should work in my opinion but it just does not.