2

我正在制作一个像 Pulse 新闻阅读器一样的水平表格视图。我在网上找到了几个示例并使其正常工作,但我想知道何时需要在转换后设置 view.frame 属性。

我发现的示例在 90 度旋转后重置垂直表视图单元格内的水平表视图框架

self.tableViewCell.horizontalTableView.transform = rotateTable;
self.tableViewCell.horizontalTableView.frame = CGRectMake(0, 0, self.tableViewCell.horizontalTableView.frame.size.width, self.tableViewCell.horizontalTableView.frame.size.height);

更多背景:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
TableViewCell *cell = (TableViewCell*)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    [[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil];

    CGAffineTransform rotateTable = CGAffineTransformMakeRotation(-M_PI_2);
    self.tableViewCell.horizontalTableView.transform = rotateTable;
    self.tableViewCell.horizontalTableView.frame = CGRectMake(0, 0, self.tableViewCell.horizontalTableView.frame.size.width, self.tableViewCell.horizontalTableView.frame.size.height);

    self.tableViewCell.contentArray = [self.arrays objectAtIndex:indexPath.section];

    self.tableViewCell.horizontalTableView.allowsSelection = YES;
    cell = self.tableViewCell;
    self.tableViewCell = nil;

}

cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;

}

但不要在单元格变换(旋转)后重置水平表格单元格的框架:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.horizontalTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {

    [[NSBundle mainBundle] loadNibNamed:@"GameTableViewCell" owner:self options:nil];
    cell = self.gameTableCell;
    self.gameTableCell = nil;
}

CGAffineTransform rotateImage = CGAffineTransformMakeRotation(M_PI_2);
cell.transform = rotateImage;
return cell;

}

我尝试重置单元格的框架,但它对输出没有影响,即使我提供了

cell.frame = CGMakeRect(200, 200, cell.frame.size.height, cell.frame.size.width)

哪个应该在表格视图周围移动单元格,不是吗?

如果我不重置self.tableViewCell.horizontalTableView.frame水平表的框架是旋转的,但是在错误的位置。

为什么我需要在旋转后重置水平表格视图的框架,而不是单个单元格(也旋转)?

谢谢!

// iPortable 插图
在此处输入图像描述

4

2 回答 2

0

啊,好的,再读一遍我明白你在问什么^^

  1. 设置框架会导致重绘视图。这需要完成,否则旧图形可能会干扰并且看起来很难看。重绘也应该锐化绘制线。
  2. 您将单元格的框架设置为其他位置(此处为 200,200),但它没有任何效果是完全正常的。单元格不能位于 以外的其他位置CGPointZero。如果你想取代它,你必须创建一个更大的视图并移动内容。(视图可以是半透明的,但它会显着减慢旧设备上的滚动速度)
  3. 你问为什么你不必重绘每个单元格而只需要重绘tableView。实际上我并不确切知道这一点,但实际上应该是表格视图的框架更改。通常情况下,通过旋转设备会发生帧变化,从而改变宽度。现在,开发人员将每个单元格更新为新大小是非常愚蠢的。感谢 Apple,tableView 为屏幕上可见的每个单元格调用必要的更新请求。最终,所有视图都调用相同的方法:drawRect:
于 2011-10-17T22:48:18.510 回答
0

我无法理解您的所有问题,但会尽力而为。
当您旋转设备时,表格视图大小会发生变化(框架)。所以你必须为表格视图设置新的框架来完成新的“设计”(将表格视图拉伸到整个宽度)。对于单元格而言,情况并非如此,因为即使在旋转之后它们也保持相同的大小。
一个例子:

________
|______| -> a cell width: 50 height: 200

旋转后:

___
| |
| | -> still the same size, width: 50 height: 200
|_|

aCGAffineTransform只是一种视觉效果。它对其子视图的大小和位置都没有影响。所以你必须为你的单元格做与你的表格视图完全相反的旋转。向哪个方向旋转是错误的?上下颠倒,向左,向右,还是您使用边缘进行旋转以使旋转点选择错误?

于 2011-10-17T19:58:02.377 回答