我正在制作一个像 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 插图