在iOS 5和6中,我在视图控制器的viewWillAppear方法中执行此操作:
UIViewController *c = [[UIViewController alloc] init];
//To avoid the warning complaining about the view not being part of the window hierarchy
[[[TWNavigationManager shared] window] addSubview:c.view];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];
[c.view removeFromSuperview];
我还在app delegate
中添加了此方法- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return [[TWNavigationManager shared] supportedInterfaceOrientationsForTopViewController];
}
这基本上转发了对顶视图控制器的调用。
这导致我的视图控制器调用自动旋转方法,然后我就可以强制该视图控制器的横向方向。 现在在iOS 7中,该代码不再起作用了。白色视图显示为全屏。
iOS7中的正确方法是什么?
提前致谢。
答案 0 :(得分:5)
遇到同样的问题并设法通过解除所呈现的动态模态视图来修复它:是。
[self dismissViewControllerAnimated:YES completion:nil];
希望有所帮助!
答案 1 :(得分:0)
我的解决方案涉及安德烈·芬纳耶夫所建议的,但我也必须设置另一种过渡风格,否则在动画结束后我得到了空白屏幕。
UIViewController *mVC = [[UIViewController alloc] init];
mVC.modalPresentationStyle = UIModalPresentationFullScreen;
mVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.navigationController presentViewController:mVC animated:NO completion:^{
[self.navigationController dismissViewControllerAnimated:YES completion:^{
}];
}];
答案 2 :(得分:0)
为了防止来自mdonia解决方案的小“闪烁”,我添加了一个dispatch_after并且能够通过动画解除虚拟模态viewController:NO
UIViewController *dummyModalVC = [UIViewController new];
[dummyModalVC setModalPresentationStyle:UIModalPresentationFullScreen];
[dummyModalVC setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[dummyModalVC.view setBackgroundColor:[UIColor purpleColor]];
[self presentViewController:dummyModalVC animated:NO completion:^{
double delayInSeconds = 0.001f;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[dummyModalVC dismissViewControllerAnimated:NO completion:^{}];
});
}];
当然看起来仍然像一个丑陋的解决方法,但我没有在给定的时间内找到更好的解决方案......;(