iOS 10:UITableViewCell的删除按钮自定义高度

Muh*_*air 1 objective-c uitableview ios10

使用自定义UITableViewCell,我试图更改tableViewCell的“删除”按钮的高度。我已经尝试过此处提供的所有解决方案。

每个人都提到过,在customTableViewCell类中,我们需要重写layoutSubviews方法并进行迭代self.subViews以找到一个应该等于UITableViewCellDeleteConfirmationView的子视图,或者在其他iOS版本中,它是UITableViewCellDeleteConfirmationControl,因此我使用了以下代码:

- (void)layoutSubviews
{
    [super layoutSubviews];

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:0.0f];

    for (UIView *subView in self.subviews) {
        NSLog(@"subview: %@", self.subviews);
        if([NSStringFromClass([subView class]) rangeOfString:@"Delete"].location != NSNotFound) {
            CGRect newFrame = subView.frame;
            newFrame.size.height = 87;
            subView.frame = newFrame;
        }
    }

    [UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)

但是self.subView只有两种观点

  • UITableViewCellContentView
  • UITableViewCellSeparatorView

如何在iOS 10+中获取tableViewCell的删除按钮视图?

编辑

这是我的视图层次结构:

在此处输入图片说明

Muh*_*air 5

对于任何正在努力解决相同问题的人。

iOS10 +中,UITableView的删除按钮的视图层次结构已更改。现在它位于UITableView-UISwipeActionPullView- UISwipeActionStandardButton下

在此处输入图片说明

因此,现在需要代替layoutSubviews迭代自定义UITableViewCell的方法,而需要迭代UITableView子视图才能获取UISwipeActionStandardButton。我发现tableView的willBeginEditingRowAtIndexPath委托是合适的地方,

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
    for (UIView *subview in tableView.subviews) {
        if ([NSStringFromClass([subview class]) isEqualToString:@"UISwipeActionPullView"]) {
            if ([NSStringFromClass([subview.subviews[0] class]) isEqualToString:@"UISwipeActionStandardButton"]) {
                CGRect newFrame = subview.subviews[0].frame;
                newFrame.size.height = 72;
                subview.subviews[0].frame = newFrame;

                //Other changes on this view can also be applied like
                subview.subviews[0].backgroundColor = [UIColor redColor];
                subview.subviews[0].layer.cornerRadius = 12;
                subview.subviews[0].layer.masksToBounds = YES;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)