在旋转时调整呈现视图的大小 [英] Resizing a presenting view on rotate
问题描述
我在视图控制器中处理旋转时遇到问题。
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.
示例:
我已将我的测试项目上传到GitHub ;您可以从 https://github.com/tewha/ResizeOnRotate.git 克隆它。
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?
编辑:
灵感通过下面的答案,一个简单的解决方法:
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;
}
推荐答案
我认为这是可能是 Apple bug 。您可以在自己的应用邮件中重现它。
I think this may be an Apple bug. You can reproduce it in their own app "Mail".
在邮件应用中重现的步骤 -
Steps to reproduce in "Mail" app -
- 在Mail应用中打开邮件收件箱。 (例如,纵向方向)
- 点击撰写邮件图标(右下角)并旋转设备(横向显示)。
- 关闭撰写邮件并立即查看收件箱消息视图。
结果:分隔线已损坏。
用户的解决方法:在消息收件箱中向下和向上滚动(导致显示刷新)。
Workaround for user: Scroll down and up in message inbox (leads to display refresh).
可重复生成iOS 7.0。 2。
Reproducible up to iOS 7.0.2.
编辑
(代码解决方法 - 1)
(Code workaround - 1)
如果可能,您可以 reloadData
在桌面视图出现时刷新它。
If possible, you could reloadData
to refresh the tableview when it appears.
- (void)viewWillAppear:(BOOL)animated
{
[self.tableView reloadData];
}
代码解决方法 - 2(仅重新加载可见单元格)
Code workaround - 2 (reload only the visible cells)
- (void)viewWillAppear:(BOOL)animated
{
NSArray *refreshCells = [self.tableView indexPathsForVisibleRows];
[self.tableView reloadRowsAtIndexPaths:refreshCells withRowAnimation:UITableViewRowAnimationNone];
}
这篇关于在旋转时调整呈现视图的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!