我有一个UISplitViewController
,它设置在我的应用程序的rootView 处。当在我的左 View Controller 中调用 viewDidLoad 时,我会进行检查,然后使用以下内容呈现模态视图 Controller :
SiteConfiguration *config = [[SiteConfiguration alloc] initWithStyle:UITableViewStyleGrouped];
config.firstLoad = YES;
UINavigationController *configNav = [[UINavigationController alloc] initWithRootViewController:config];
if ([Utility isIpad]) {
configNav.modalPresentationStyle = UIModalPresentationFormSheet;
configNav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[[AppDelegate instance].splitViewController presentModalViewController:configNav animated:YES];
} else {
[self presentModalViewController:configNav animated:YES];
}
如果在加载应用程序时 iPad 处于横向模式,则 modalView 显示的方向不正确:
我可以旋转 iPad 来解决这个问题,但为什么它加载错误?我的 SiteConfiguration
viewController 中的 shouldAutorotateToInterfaceOrientation:
返回 YES。可能是什么原因造成的?
最佳答案
请注意您选择在何处展示模态 Controller 。 我有一些自定义模态 Controller 的经验,并在
中设置模态 Controller 的方向(及其阴影!) - (void)viewDidLoad:(BOOL)animated
并不总是按预期行事。
将您的代码(presentModalViewController:configNavanimated:YES
)放入
- (void)viewDidAppear:(BOOL)animated
instead. (Do this as well with any code that sets a subviews frame or does any manipulation of layers, e.g. the shadow layer and shadow properties).
As far as I can tell, the rotation may not be apparent to subviews of the rotated view until after
- (void)viewDidLoad:(BOOL)animated
由于线程问题(在主线程将旋转传递到 subview (和模态 Controller )之前,一个线程可能会开始绘制 subview 或模态 Controller 的 View )。比我拥有更多线程经验的人可能能够对此有更多的了解。
关于objective-c - 从 UISplitViewController 呈现的 modalViewController 出现错误的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11568023/