我有一个带有其约束的子视图,该子视图已通过IBOutlet引用了超级视图,我通过取消激活约束然后给出新值并再次激活来更改约束,这种方法工作正常且没有警告,但是当设备旋转并发生故障时会出现问题似乎正在添加另一个约束(我在情节提要中添加的约束) 代码:
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
旋转后警告:
"<NSLayoutConstraint:0x600003fdce60 UIView:0x7fc034f050b0.bottom == PlayKit.PlayerView:0x7fc034f69870.bottom + 143.333 (active)>", "<NSLayoutConstraint:0x600003fe3480 'bottomViewId' V:[UIView:0x7fc034f050b0]-(0)-| (active, names: '|':PlayKit.PlayerView:0x7fc034f69870 )>"
答案 0 :(得分:0)
您需要viewDidLoad
中的一个
var bottomViewBottomConstraint:NSLayoutConstraint!
bottomViewBottomConstraint = bottomView.bottomAnchor.constraint(equalTo: playerView.bottomAnchor,constant:0)
并不断播放
bottomViewBottomConstraint.constant = self.isHide ? 0 : bottomView.frame.height + 50
self.view.layoutIfNeeded()