I want to change the positions of my view programmatically at runtime using constraints I have following arrangement of views
|
viewA
|
viewB
|
viewC
say i have viewA with topAnchor constraints set to top of margin of parent view and viewB with topAnchorset to viewA and so on for viewC
And i want to change the position of these views on certain action at runtime
|
viewA
|
viewC
|
viewB
i have store two different constraints for viewB one with top of viewA and another with top of viewC
viewBTopConstraints = viewB.topAnchor.constraint(equalTo: viewA.bottomAnchor, constant: TOP_SPACE)
newViewBTopConstraints = viewB.topAnchor.constraint(equalTo: viewC.bottomAnchor, constant: TOP_SPACE)
In my toggle action method i have done something like this
viewBTopConstraints?.isActive = false
newViewBTopConstraints?.isActive = true
This works on first run of action however it fails on second time, on further debugging in view debugger i found out that it creates duplicate constraints rather that changing the original one.
isActiveafter the first time.