additional constraint is created when device rotation changes

Viewed 52

I have a subview with its constraint that has reference to super view via IBOutlet, I'm changing the constraint by deactivating it then giving new value and activating again , this works fine and no warnings but the problem occurs when device rotates and it seems another constraint is getting added ( the constraint that I've added in storyboard) code:

bottomViewBottomConstraint.isActive = false
if self.isHide {
    bottomViewBottomConstraint = bottomView.bottomAnchor.constraint(equalTo: playerView.bottomAnchor,constant:0)
}
else {
    bottomViewBottomConstraint = bottomView.bottomAnchor.constraint(equalTo: playerView.bottomAnchor,constant:bottomView.frame.height + 50)
}
bottomViewBottomConstraint.isActive = true

warning after rotation:

"<NSLayoutConstraint:0x600003fdce60 UIView:0x7fc034f050b0.bottom == PlayKit.PlayerView:0x7fc034f69870.bottom + 143.333   (active)>",
"<NSLayoutConstraint:0x600003fe3480 'bottomViewId' V:[UIView:0x7fc034f050b0]-(0)-|   (active, names: 
'|':PlayKit.PlayerView:0x7fc034f69870 )>"

Bottom view storyboard constraint enter image description here

1 Answers

You need it one in viewDidLoad

var bottomViewBottomConstraint:NSLayoutConstraint!

bottomViewBottomConstraint = bottomView.bottomAnchor.constraint(equalTo: playerView.bottomAnchor,constant:0)

and play with constant

bottomViewBottomConstraint.constant = self.isHide ? 0 :   bottomView.frame.height + 50
self.view.layoutIfNeeded()
Related