項目需求要求點擊按鈕,批量刪圖標(biāo)在右邊而不是默認(rèn)的左邊,蛋疼了2天,百度是找的都是在左邊,終于解決
Simulator Screen Shot 2016年9月21日 下午2.52.06.png
使用Masonry 重置約束
#pragma mark - 編輯按鈕事件
-(void)editBtnAction{
//更改約束
NSArray *cellArray = [self cellsForTableView:self.tableView];
if ([self.editBtn.titleLabel.text isEqualToString:@"編輯"]) {
for (StoreShopsListCell *cell in cellArray) {
[UIView animateWithDuration:1 animations:^{
[cell.deleteBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(cell.contentView.mas_right).offset(-70);
make.top.equalTo(cell.contentView);
make.bottom.equalTo(cell.contentView).offset(1);
make.width.equalTo(cell.contentView);
}];
[cell.addBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(cell.contentView.mas_right).offset(-80);
make.bottom.mas_equalTo(cell.shopImageView.mas_bottom).offset(0);
make.width.height.mas_equalTo(20);
}];
[cell.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(cell.contentView.mas_right).offset(-70);
make.left.mas_equalTo(cell.shopImageView.mas_right).offset(10);
make.top.mas_equalTo(cell.shopImageView.mas_top).offset(-3);
make.height.mas_equalTo(20);
}];
}];
}
[self.editBtn setTitle:@"完成" forState:(UIControlStateNormal)];
[self.editBtn setTitleColor:UIColorFromRGB(0x00bb9c) forState:(UIControlStateNormal)];
}else{
[_editBtn setTitle:@"編輯" forState:(UIControlStateNormal)];
[_editBtn setTitleColor:UIColorFromRGB(0x43515a) forState:(UIControlStateNormal)];
for (StoreShopsListCell *cell in cellArray) {
[UIView animateWithDuration:1 animations:^{
[cell.deleteBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(cell.contentView.mas_right).offset(0);
make.top.equalTo(cell.contentView);
make.bottom.equalTo(cell.contentView).offset(1);
make.width.equalTo(cell.contentView);
}];
[cell.addBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(cell.contentView.mas_right).offset(-10);
make.bottom.mas_equalTo(cell.shopImageView.mas_bottom).offset(0);
make.width.height.mas_equalTo(20);
}];
[cell.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(cell.contentView.mas_right).offset(-10);
make.left.mas_equalTo(cell.shopImageView.mas_right).offset(10);
make.top.mas_equalTo(cell.shopImageView.mas_top).offset(-3);
make.height.mas_equalTo(20);
}];
}];
}
}
}
- 獲取去不cell的方法 包括看不到的cell
//獲取所有包括看不到的cell
-(NSArray *)cellsForTableView:(UITableView *)tableView
{
NSInteger sections = tableView.numberOfSections;
NSMutableArray *cells = [[NSMutableArray alloc] init];
for (int section = 0; section < sections; section++) {
NSInteger rows = [tableView numberOfRowsInSection:section];
for (int row = 0; row < rows; row++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
[cells addObject:[tableView cellForRowAtIndexPath:indexPath]];
}
}
return cells;
}