FluentLayout / Cirrious.FluentLayout

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

WithMultiplier(0.667f) works but WithMultiplier((float)(4/6)) does not work #36

Closed flyingxu closed 7 years ago

flyingxu commented 7 years ago

this code is working fine: button.AtBottomOf(View).WithMultiplier(0.667f), but if I change the float to some expression like the following, it will not work: button.AtBottomOf(View).WithMultiplier((float)(4/6)), it crashes at runtime with exception:

Received unhandled ObjectiveC exception: NSInvalidArgumentException NSLayoutConstraint for <UIButton: 0x17264840; frame = (0 0; 0 0); opaque = NO; layer = <CALayer: 0x17264660>>: 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.

gshackles commented 7 years ago

The error is saying that you're specifying a multiplier of 0, which is what's happening here. The issue is that you're dividing two ints, so (4 / 6) == 0. If you change that to button.AtBottomOf(View).WithMultiplier(4/6f) you should get the behavior you were expecting.

flyingxu commented 7 years ago

oh God, I must be drunk that day.