ios - iOS Masonry,如果另一个视图的 centerX 依赖于它,则视图的大小约束不起作用
问题描述
我在我的项目中使用 Masonry。首先,我对 rightToolBar 做了一些限制:
CGSize rightToolBarSize = CGSizeMake(54, 210);
[self.rightToolBar mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self).offset(-10);
make.bottom.equalTo(self.mas_bottom).mas_offset(-20);
make.size.mas_equalTo(rightToolBarSize);
}];
然后是另一个视图,头像:
[self.avatar mas_remakeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(50, 50));
make.bottom.equalTo(self.rightToolBar.mas_top).with.offset(-10);
make.centerX.equalTo(self.rightToolBar.mas_centerX);
}];
这使得self.rightToolBar 的宽度变得比我预期的大 74 、 20 。如果我将头像的约束更改为:
[self.avatar mas_remakeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(50, 50));
make.bottom.equalTo(self.rightToolBar.mas_top).with.offset(-10);
make.right.equalTo(self).with.offset(-17); // centerX -> right
}];
现在self.rightToolBar 的宽度是 54。但这没有任何意义,为什么设置头像的centerX会改变rightToolBar的宽度呢?
解决方案
也许您应该删除 rightToolBar 的约束并重新制作
[self.rightToolBar removeConstraints:self.constraints.constraints];
[self.rightToolBar mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self).offset(-10);
make.bottom.equalTo(self.mas_bottom).mas_offset(-20);
make.size.mas_equalTo(rightToolBarSize);
}];
推荐阅读
- python - 无法在 Pycharm 上安装 Pandas,接收错误
- spring-integration - GlobalChannelInterceptor 传递模式数组
- typescript - 如何创建混合模式以将事件冒泡到继承层次结构中?
- python - 使用 Telegram Bot 按下按钮时如何返回命令
- php - 将数组转换为查询php
- php - 找不到电报帐户类型
- python - python将现有变量获取到列表中
- python - 我正在尝试迭代一个函数的返回值,该函数返回一个由 3 个元组组成的元组
- crafter-cms - CrafterCMS:application.properties 位置
- c# - 拆分逗号分隔的字符串并存储到变量中