我希望重新排序图(三行)显示在 UITableViewCell 的左侧,因为右侧将被覆盖的 UIView 隐藏。
我找到的这段代码:
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
for(UIView* view in cell.subviews)
{
if([[[view class] description] isEqualToString:@"UITableViewCellReorderControl"])
{
// Creates a new subview the size of the entire cell
UIView *movedReorderControl = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(view.frame), CGRectGetMaxY(view.frame))];
// Adds the reorder control view to our new subview
[movedReorderControl addSubview:view];
// Adds our new subview to the cell
[cell addSubview:movedReorderControl];
// CGStuff to move it to the left
CGSize moveLeft = CGSizeMake(movedReorderControl.frame.size.width - view.frame.size.width, movedReorderControl.frame.size.height - view.frame.size.height);
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformTranslate(transform, -moveLeft.width, -moveLeft.height);
// Performs the transform
[movedReorderControl setTransform:transform];
}
}
}
第一次加载表时工作正常。 但是,当单元格“重绘”时(例如前后滚动时),重新排序符号就会消失。
出了什么问题?
最佳答案
您不断移动重新排序控件相对于其当前位置的位置
CGSize moveLeft = CGSizeMake(movedReorderControl.frame.size.width - view.frame.size.width, movedReorderControl.frame.size.height - view.frame.size.height);
所以看起来像是将其移出了屏幕。尝试存储初始帧,然后使用它来移动 subview :
CGSize moveLeft = CGSizeMake(initialFrame.width - view.frame.size.width, initialFrame.width.height - view.frame.size.height);
关于ios - 将重新排序符号放在 UITableViewCell 的左侧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15260976/