何时需要重置iOS转换后的view.frame属性

我正在制作一个像Pulse新闻阅读器一样的水平表格视图。 我已经find了几个在线的例子,并使其工作,但我想知道什么时候我们需要在转换后设置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的插图
在这里输入图像说明

呃再次阅读之后,我确定你在问什么^^

  1. 设置框架会导致重绘视图。 这需要做,否则旧的graphics可能会干扰,它看起来很丑。 重画也应该磨平画线。
  2. 你设置你的细胞的框架被放置在其他地方(在这里200,200),但这是完全正常的,它没有效果。 一个单元格不能在CGPointZero以外的CGPointZero 。 如果您想取代它,则必须创build更大的视图并移动内容。 (视图可以是半透明的,但是会显着减慢旧设备的滚动速度)
  3. 你问为什么你不必重绘每个单元格,但只有tableView。 其实我并不完全知道,但实际上应该是表格视图的改变。 通常情况下,通过旋转设备来改变帧的宽度。 现在,开发人员更新每个单元格以获得新的大小将是非常愚蠢的。 感谢Apple,tableView为每个在屏幕上可见的单元格调用必要的更新请求。 最终所有视图都会调用相同的方法: drawRect:

我有问题了解你所有的问题,但会尽我所能。
当您旋转设备时,表视图大小会改变(框架)。 所以你必须设置表格视图的新框架来完成新的“devise”(将表格视图拉伸到整个宽度)。 对于细胞来说这不是真的,因为即使在旋转之后它们保持相同的大小。
一个例子:

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

旋转后:

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

CGAffineTransform只是一个视觉效果。 它的大小没有影响它的子视图的位置。 所以你必须为你的单元格进行完全相反的旋转,然后为你的表格视图。 在哪个方向错误旋转? 颠倒,左,右,还是你用旋转的边缘,使旋转点是错误的select?