ios - 设备旋转更改时会创建附加约束
问题描述
我有一个子视图,其约束通过 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 )>"
解决方案
你需要它一个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()
推荐阅读
- javascript - Paperjs 在不使用 Paperjs 代码时导致类语法错误
- javascript - Javascript 表单验证不适用于注册弹出表单
- c# - 在 Entity Framework Core 3 中使用 TransactionScope 时,SET IDENTITY_INSERT 不起作用
- r - 在 ggplot2 刻面之间添加空格和三个点(省略号)以指示省略的刻面
- javascript - VueJS 在创建的函数中返回未定义
- c# - 绑定到 Entry.Text 的属性设置器无限循环
- python - 避免 django 设置文件中的代码重复
- opencv - openCV Canny 边缘检测改进
- java - 错误:COPY 转义必须是单个单字节字符(多分隔符似乎适用于 Postgres 9.0,但不适用于 Postgres 9.2)
- java - Why do these rectangles sometimes show that they are colliding even though they are not?