Toggle Limit Under Specific Condition

Setting: I designed UIButton

with lower constraint

X, priority 999. In addition to this, it constraint

UIButton

also has another constraint

Y, priority 1000, but this one is marked installed = false

.

Y is linked to @IBOutlet

in mine UIViewController

with strong link.

Q viewDidLoad()

: If the given condition is true, I activate constraint

Y by executing Y.isActive = true

and then view.layoutIfNeeded()

, which eventually calls updateConstraints()

, if necessary. If the condition is false, then I don't do anything.

My expectation: when the condition is true, I expect the view to apply Y constraint

to the button and discard the X. When the condition is false, I expect to UIButton

have only constraint

X.

Result: It seems that constraint

Y does not apply at all even if the condition is met.

I would appreciate any thoughts on this, it seems to me to be something that should work.

Thank.

PS I use quickly, but I don't mind if the answer is provided in Obj-C.

+3


source to share


1 answer


It seems that a bug when using IB, where setting a constraint property as uninstalled will not always work properly as "inactive", but would rather create problems when activating / deactivating the constraint.

Always specify the restrictions as set as a workaround, but for those restrictions that should be inactive at boot, go to the user-defined id / user validation attributes and add "active" as a boolean to false (unchecked)



Found the solution here: fooobar.com/questions/707765 / ...

-1


source







All Articles