I'm making a horizontal table view like the Pulse news reader. I've found several examples online and have it working, but am wondering when we need to set the view.frame property after a transformation.
The examples I've found reset the frame of the horizontal table view within the vertical table view cell after the 90 degree rotation
self.tableViewCell.horizontalTableView.transform = rotateTable;
self.tableViewCell.horizontalTableView.frame = CGRectMake(0, 0, self.tableViewCell.horizontalTableView.frame.size.width, self.tableViewCell.horizontalTableView.frame.size.height);
More Context:
- (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;
}
But don't reset the frame of the horizontal table cell after the cell's transformation (rotation):
- (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;
}
I tried resetting the cell's frame and it had no effect on the output, even if I supplied
cell.frame = CGMakeRect(200, 200, cell.frame.size.height, cell.frame.size.width)
Which should have moved the cell around the Table View, no?
If I don't reset the frame of self.tableViewCell.horizontalTableView.frame
the horizontal table is rotated, but in the wrong location.
Why is it that I need to reset the frame of the horizontal Table View after rotating it, but not the individual cells (which are also rotated)?
Thanks!
// illustration by iPortable