“This is the 14th day of my participation in the First Challenge 2022. For details: First Challenge 2022.”
The introduction
Application Scenarios:
- Sub-orders do not display policy information
- The upper and lower order lists show different subviews
The order list at this level does not display the distribution terminal button subview
The sub-agent’s order list displays the distribution terminal button subview
- Display the audit button when there is no audit status in the details interface of warehousing order, otherwise hide the audit button)
I Dynamic control using installation and removal of MASConstraint
1. Define the MASConstraint attribute 2. Store the MASConstraint attribute. 3. Remove and unload specific constraints based on specific conditions
1.1 Sub-orders do not display policy information
Install and remove using MASConstraint
[self.noLab mas_updateConstraints:^(MASConstraintMaker *make) {
self.makeheight4noLab = make.height.mas_equalTo(kAdjustRatio(0));
}];
if(models.isLowerOrder){// Subordinates do not display policy information
[self.makeheight4noLab install];
}else{[self.makeheight4noLab uninstall];
}
Copy the code
1.2 Unaudited status display audit button on details interface of warehouse entry order, otherwise hidden.
- Comparison of effects before and after
Specific use method:
1.1 Define the MASConstraint attribute
1.2 Store the MASConstraint attribute
1.3 Remove and unload specific constraints based on the use of containing specific fields models.tradeno
- Define the MASConstraint attribute
/** Remove and install constraints at the bottom of the image */
@property MASConstraint *makebottomequalToWeakSelf4imgV;
Copy the code
- Store the MASConstraint attribute
__weak __typeof__(self) weakSelf = self;
[self.imgV mas_updateConstraints:^(MASConstraintMaker *make) {
self.makebottomequalToWeakSelf4imgV = make.bottom.equalTo(weakSelf).offset(-kAdjustRatio(14));
}];
Copy the code
- Remove and unload specific constraints based on the use of containing specific fields models.tradeno
if(! weakSelf.viewModel.isShowBottomBtn){ [self.makebottomequalToWeakSelf4TV install];
}else{[self.makebottomequalToWeakSelf4TV uninstall];
}
Copy the code
II Update view height constraints to dynamically control the display and hiding of subview buttons
Requirement: Dynamic control of subview button display and hide
Example: The order list of this level does not display the distribution terminal button subview. The order list of a subordinate agent displays the distribution terminal button subview
The height constraint of the view is controlled according to the type of the upper and lower levels of the model, thus controlling the display and hiding of the view
- Define assign terminal button properties
/** Assign terminal button */
@property (strong.nonatomic) QCTStoreOrderButton *allocationBtn;
- (QCTStoreOrderButton *)allocationBtn{
if(! _allocationBtn) { QCTStoreOrderButton *tmp = [[QCTStoreOrderButton alloc]init]; _allocationBtn = tmp; [tmp setTitle:QCTLocal(@" Distribution terminal") forState:UIControlStateNormal];
__weak __typeof__(self) weakSelf = self;
[self addSubview:tmp];
[tmp mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(kAdjustRatio(25));
make.width.mas_greaterThanOrEqualTo(kAdjustRatio(70));
make.right.equalTo(weakSelf).offset(-kAdjustRatio(kSideMargin));
make.top.equalTo(weakSelf.quantityAllottedLab.mas_bottom).offset(kAdjustRatio(6));
make.bottom.equalTo(weakSelf).offset(-kAdjustRatio(13));
// make.size.mas_equalTo(CGSizeMake(kAdjustRatio(74), kAdjustRatio(28)));
}];
[tmp.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.offset(kAdjustRatio(3));
make.right.offset(kAdjustRatio(- 3));
}];
tmp.titleLabel.textAlignment = NSTextAlignmentCenter;
}
return _allocationBtn;
}
Copy the code
- The height constraint of the view is controlled according to the type of the upper and lower levels of the model, thus controlling the display and hiding of the view
__weak __typeof__(self) weakSelf = self;
[self.allocationBtn mas_updateConstraints:^(MASConstraintMaker *make) {
if(! models.isLowerOrder){// "isLowerOrder" : "false"
make.top.equalTo(weakSelf.quantityAllottedLab.mas_bottom).offset(kAdjustRatio(0));
make.height.mas_equalTo(kAdjustRatio(0));
}else{/ / at a lower level
make.top.equalTo(weakSelf.quantityAllottedLab.mas_bottom).offset(kAdjustRatio(6));
make.height.mas_equalTo(kAdjustRatio(30)); }}];Copy the code
see also
Due to space reasons, more content please pay attention to # small program: iOS reverse, only for you to present valuable information, focus on mobile technology research field; For more services and advice, please follow # publicid: iOS Reverse.