覆盖整个单元格的UITableView重新排序按钮
问题描述:
我一直试图使用this tutorial使重新排序按钮覆盖整个单元格。它很好用,直到细胞从视图中消失。一旦你回到牢房,重新排序按钮已经转移了很多。覆盖整个单元格的UITableView重新排序按钮
在此图片中,红色代表重新排序按钮。
这是本教程中使用的代码。
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// Grip customization code goes in here...
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];
[resizedGripView release];
CGSize sizeDifference = CGSizeMake(resizedGripView.frame.size.width - view.frame.size.width, resizedGripView.frame.size.height - view.frame.size.height);
CGSize transformRatio = CGSizeMake(resizedGripView.frame.size.width/view.frame.size.width, resizedGripView.frame.size.height/view.frame.size.height);
// Original transform
CGAffineTransform transform = CGAffineTransformIdentity;
// Scale custom view so grip will fill entire cell
transform = CGAffineTransformScale(transform, transformRatio.width, transformRatio.height);
// Move custom view so the grip's top left aligns with the cell's top left
transform = CGAffineTransformTranslate(transform, -sizeDifference.width/2.0, -sizeDifference.height/2.0);
[resizedGripView setTransform:transform];
for(UIImageView* cellGrip in view.subviews)
{
if([cellGrip isKindOfClass:[UIImageView class]])
[cellGrip setImage:nil];
}
}
}
}
如何防止重新订购控制向左移动?我试图再次转换转换,但这只是让重新排序控制完全脱离屏幕。使代码向左移动以及如何修复代码的代码有什么问题?
答
我想出了如何做到这一点!我不得不添加一个属性到存储resizedGripView的初始框架的viewController。事实证明,每次调用方法时(每次单元格再次出现时),重新排序按钮都将从当前位置移开,因此我必须将其存储在初始位置。
UIView* resizedGripView = [[UIView alloc] init];
if (!initialFrame.size.height)
[resizedGripView setFrame: CGRectMake(0, 0, CGRectGetMaxX(view.frame), CGRectGetMaxY(view.frame))];
else
[resizedGripView setFrame: initialFrame];
if (!initialFrame.size.height)
[self setInitialFrame: resizedGripView.frame];
你的问题是?你给出了一个问题,但没有真正问任何具体的问题。请给我们一些更具体的东西。 – 2013-04-21 18:42:12
我更新了问题 – bbraunj 2013-04-22 01:27:23