(解决方案,不是问题,我会立即回答)
当 anUITableViewController
自动旋转时,它UITableView
会自动调整大小,但它的单元格不会调整大小,甚至在旋转后定位错误。
特别是在分页的情况下,情况更糟。您可以设置单元格的高度和高度pagingEnabled
来呈现分页。然而,在自动旋转之后,一切都变得一团糟。YES
[UITableView bounds].size.height
UITableView
如何通过表格视图旋转自动调整这些单元格的大小?
(解决方案,不是问题,我会立即回答)
当 anUITableViewController
自动旋转时,它UITableView
会自动调整大小,但它的单元格不会调整大小,甚至在旋转后定位错误。
特别是在分页的情况下,情况更糟。您可以设置单元格的高度和高度pagingEnabled
来呈现分页。然而,在自动旋转之后,一切都变得一团糟。YES
[UITableView bounds].size.height
UITableView
如何通过表格视图旋转自动调整这些单元格的大小?
做一个UITableViewController
这样的。核心概念是beginUpdate
旋转之前和endUpdate
旋转之后。只有这些,单元格的自动调整大小将自动完成。但是,他们的定位不会。所以我添加了一个手动滚动到特定位置。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [tableView bounds].size.height;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[[self tableView] beginUpdates];
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
[[self tableView] endUpdates];
// We have to specify an position to scroll to explicitly and manually
// becase current page number is no determinable especially if user rotate device continually.
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[[self tableView] scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
- (void) viewDidLoad
{
[super viewDidLoad];
[[self tableView] setPagingEnabled:YES];
}