iOS自定义表格视图单元格在编辑模式下resize

编辑UITableView ,圆形红色按钮和删除按钮与自定义单元格重叠。

我们如何调整自定义单元格的大小,为红色圆形按钮和删除按钮留出空间。

使用此代码,您可以执行不同的任务,具体取决于编辑单元格的方式和阶段。我对代码进行了大量评论,因为我花了这么长时间来自行解决这个问题。 (变得混乱)

  - (void)willTransitionToState:(UITableViewCellStateMask)state { [super willTransitionToState:state]; if (state == UITableViewCellStateDefaultMask) { NSLog(@"Default"); // When the cell returns to normal (not editing) // Do something... } else if ((state & UITableViewCellStateShowingEditControlMask) && (state & UITableViewCellStateShowingDeleteConfirmationMask)) { NSLog(@"Edit Control + Delete Button"); // When the cell goes from Showing-the-Edit-Control (-) to Showing-the-Edit-Control (-) AND the Delete Button [Delete] // !!! It's important to have this BEFORE just showing the Edit Control because the edit control applies to both cases.!!! // Do something... } else if (state & UITableViewCellStateShowingEditControlMask) { NSLog(@"Edit Control Only"); // When the cell goes into edit mode and Shows-the-Edit-Control (-) // Do something... } else if (state == UITableViewCellStateShowingDeleteConfirmationMask) { NSLog(@"Swipe to Delete [Delete] button only"); // When the user swipes a row to delete without using the edit button. // Do something... } } 

你说你添加了自定义标签,但没有,我在使用tableviews之前也做过同样的事情。 我通常喜欢使用动画块“隐藏”重叠的视图,如:

 [UIView animateWithDuration:0.3 animations:^ { self.myTableCellSubview.alpha = 0.0f; } ]; 

在上面的每个if语句中,并根据状态将alpha从1.0f更改为0.0f。

对于通常的缩进,在属性检查器中,确保选中“编辑时缩进”,您也可以通过以下方式以编程方式设置:

 cell.shouldIndentWhileEditing = YES; 

如果这不起作用,您可能会在自动调整过程中出现一些奇怪之处。 在故事板或xib中,选择需要缩进的单元格的子视图,然后转到“大小”检查器(标尺选项卡)。 如果子视图需要从左侧缩进(—>),请确保它固定在左侧:

在此处输入图像描述

如果子视图需要从右侧缩进(<---),请确保它固定在右侧:

在此处输入图像描述

希望这可以帮助!

您可以覆盖我认为的这些方法之一并调整自定义单元格的大小。 根据这个问题,不确定这正是你所要求的。

 - (void)willTransitionToState:(UITableViewCellStateMask)state - (void)didTransitionToState:(UITableViewCellStateMask)state