我正在尝试将重新排序控件移动到单元格的左侧。我正在使用自定义单元格,我的单元格有按钮。我实际上可以通过使用以下函数将其向左移动。但我的右键最初是默认重新排序控件的位置,因此即使应用了变换后也无法访问。可以访问不在后面的部分。
作为参考,我使用了以下链接 http://b2cloud.com.au/how-to-guides/reordering-a-uitableviewcell-from-any-touch-point
How to make reorder control of UITableViewCell in left side?
#pragma mark -
#pragma mark rows reordering
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
for(UIView* view in cell.subviews)
{
if([[[view class] description] isEqualToString:@"UITableViewCellReorderControl"])
{
UIView* resizedGripView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(view.frame), 48)];
[resizedGripView setBackgroundColor:[UIColor whiteColor]];
[resizedGripView addSubview:view];
[cell addSubview:resizedGripView];
// Original transform
const CGAffineTransform transform = CGAffineTransformMakeTranslation(40 - cell.frame.size.width, 1);
[resizedGripView setTransform:transform];
/*for(UIImageView* cellGrip in view.subviews)
{
if([cellGrip isKindOfClass:[UIImageView class]])
[cellGrip setImage:nil];
}*/
}
}
}
请参阅此图片http://i.stack.imgur.com/xBDLG.png
在重新排序控件的原始位置无法访问单元格中的编辑按钮。休息工作正常。
答案 0 :(得分:2)
Xcode 8.2.1, Swift 3.x
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.subviews.forEach() {
if ($0.description.range(of: "UITableViewCellReorderControl") != nil) {
let resizedGripView = UIView(frame: CGRect(x: 0, y: 0, width: $0.frame.maxX, height: $0.frame.maxY))
resizedGripView.addSubview($0)
cell.addSubview(resizedGripView)
let transform = CGAffineTransform(translationX: $0.frame.size.width - cell.frame.size.width, y: 1)
resizedGripView.transform = transform
}
}
}
答案 1 :(得分:1)
试试这个,我希望有所帮助
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath
{
for(UIView* view in cell.subviews)
{
if([[[view class] description] isEqualToString:@"UITableViewCellReorderControl"])
{
UIView* resizedGripView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(view.frame), CGRectGetMaxY(view.frame))];
[resizedGripView addSubview:view];
[cell addSubview:resizedGripView];
// Original transform
const CGAffineTransform transform = CGAffineTransformMakeTranslation(view.frame.size.width - cell.frame.size.width, 1);
// Move custom view so the grip's top left aligns with the cell's top left
[resizedGripView setTransform:transform];
}
}
}