我有一个 uitableview,我旋转了 180 度,但我已经将其单元格旋转了 -180 度。结果是我从 TableView 的底部加载我的数据。这很好用。当我尝试重新排序单元格时,问题就来了。如果我尝试拖动一个单元格,它的移动会反转并立即跳到表格 View 的顶部/底部,具体取决于我拖动的方向。
查看此内容的最简单方法是使用包含核心数据的主从模板开始一个新项目。在OIMasterViewConroller.m文件处
CGAffineTransform transform = CGAffineTransformMakeRotation(-3.14159);
self.tableView.transform = transform;
在viewDidLoad方法中,放置
CGAffineTransform transform = CGAffineTransformMakeRotation(-3.14159);
cell.transform = transform;
在 configureCell 方法中。最后,更改 canMoveRowAtIndexPath 以返回 YES 并实现空白
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
运行项目并使用 + 按钮向 TableView 添加一些项目。然后单击编辑按钮并尝试重新排序。
我认为问题出在单元格上,因为移除单元格上的旋转将停止这种奇怪的行为,即使表格是颠倒的。
我考虑过只旋转单元格内的文本,但删除按钮倒置了,而且在错误的一侧。
最佳答案
因此,我最终对 TableView 和 TableView 中使用的单元格进行了子类化。以下是我所做的一些工作:
在 tableview 子类中,我重载了 layoutsubviews:
- (void)layoutSubviews
{
[super layoutSubviews];
for (UIView *subview in self.subviews) {
if ([NSStringFromClass([subview class]) isEqualToString:@"UIShadowView"]) {
subview.hidden = YES;
}
}
}
这将删除阴影。如果你不这样做,阴影会在重新排序时显示在 tableviewcells 的顶部。
对于 tableviewcell 子类,我更改了它的 layoutSubviews,如下所示:
- (void)layoutSubviews
{
[super layoutSubviews];
for (UIView *subview in self.subviews) {
if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {
CGRect newFrame = subview.frame;
newFrame.origin.x = 0;
subview.frame = newFrame;
subview.transform = CGAffineTransformMakeRotation(-M_PI);
}
else if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellEditControl"]) {
CGRect newFrame = subview.frame;
newFrame.origin.x = 320-newFrame.size.width;
subview.frame = newFrame;
subview.transform = CGAffineTransformMakeRotation(-M_PI);
}
else if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellReorderControl"]) {
CGRect newFrame = subview.frame;
newFrame.origin.x = 0;
subview.frame = newFrame;
}else if([NSStringFromClass([subview class]) isEqualToString:@"UIButton"]) {
CGRect newFrame = subview.frame;
newFrame.origin.x = 0;
subview.frame = newFrame;
subview.transform = CGAffineTransformMakeRotation(-M_PI);
}else{
subview.transform = CGAffineTransformMakeRotation(-M_PI);
}
}
}
这将旋转并移动所有删除按钮/指示器等。需要注意的重要一点是我们不旋转 UITableViewCellReorderControll。旋转此 subview 是导致重新排序困惑的原因。
关于ios - 重新排序旋转的 uitableviewcell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14082111/