In one of my controllers I'm using UICollectionView with two-sided cells (there is a button on the face side of the cell, and if user is tapping it cell should show him/her the other side of the cell).
so I have this in my cell class:
firstView = UIView()
...
self.addSubview(firstView)
infoView = UIView()
...
self.insertSubview(infoView, belowSubview: firstView)
Both views have a lot of elements in them, for structuring these elements I'm using mostly Visual Format constraints and anchors.
i.e.
let topFirstViewConstraint = firstView.topAnchor.constraint(equalTo: self.topAnchor, constant: 4)
allConstraints.append(topFirstViewConstraint)
...
let goButtonCenter = goButton.centerXAnchor.constraint(equalTo: firstView.centerXAnchor, constant: 0)
allConstraints.append(goButtonCenter)
For switching between face and rear views I'm using UIView.transition:
UIView.transition(from: firstView, to: infoView, duration: 0.2, options: .transitionFlipFromLeft) { (success) in
}
It works like a charm, I don't have any autoLayout errors at all.
But if I'm trying to switch from firstView
to infoView
firstView
constraints goes wild and vice versa (I still don't have any errors but I know how these views should look, and it's a mess). I've tried to use self.updateConstraints()
in transition closure but it doesn't work.
Did anyone experience something like that?
https://developer.apple.com/documentation/uikit/uiview/1622562-transition says:
What happens with constraints when one party of a constraint gets removed from superview? It definitely doesn‘t work anymore.
What you can try