问题
I'm having a problem handling rotation in a view controller.
When the view is topmost and the phone is rotated, it adapts correctly.
When there's a view controller being presented modally over it and the device is rotated, the view controller under is not fully updated for the rotation when the user returns. The biggest problem I appear to be having is that the separator lines don't expand to fill the whole width.
Example:
I've uploaded my test project to GitHub; you can clone it from https://github.com/tewha/ResizeOnRotate.git.
I have no code handling rotation at all. My understanding was that this was supposed to be fully automatic. What am I missing to make this work correctly?
Edit:
Inspired by the answer below, a simple workaround:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
UITableViewCellSeparatorStyle separatorStyle = self.tableView.separatorStyle;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.separatorStyle = separatorStyle;
}
回答1:
I think this may be an Apple bug. You can reproduce it in their own app "Mail".
Steps to reproduce in "Mail" app -
- Open Inbox of messages in "Mail" app. (say, in Portrait orientation)
- Tap compose message icon (bottom right) and rotate the device (in landscape).
- Close the compose message and see the inbox messages view now.
Result: The separator lines are broken.
Workaround for user: Scroll down and up in message inbox (leads to display refresh).
Reproducible up to iOS 7.0.2.
Edit
(Code workaround - 1)
If possible, you could reloadData
to refresh the tableview when it appears.
- (void)viewWillAppear:(BOOL)animated
{
[self.tableView reloadData];
}
Code workaround - 2 (reload only the visible cells)
- (void)viewWillAppear:(BOOL)animated
{
NSArray *refreshCells = [self.tableView indexPathsForVisibleRows];
[self.tableView reloadRowsAtIndexPaths:refreshCells withRowAnimation:UITableViewRowAnimationNone];
}
来源:https://stackoverflow.com/questions/19390566/resizing-a-presenting-view-on-rotate