Ios7 在一个视图控制器中强制横向定位
在iOS 5和iOS 6中,我在我的视图控制器中的ViewWillAspect方法中执行此操作:Ios7 在一个视图控制器中强制横向定位,ios7,autorotate,Ios7,Autorotate,在iOS 5和iOS 6中,我在我的视图控制器中的ViewWillAspect方法中执行此操作: 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]
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委托中添加了这个方法
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return [[TWNavigationManager shared] supportedInterfaceOrientationsForTopViewController];
}
它基本上会将该调用转发给俯视图控制器
这导致对我的视图控制器调用自动旋转方法,然后我就能够强制该视图控制器的横向方向。
现在在iOS 7中,该代码不再工作。全屏显示白色视图
iOS7中的正确方法是什么
提前感谢。遇到了同样的问题,并通过取消显示的模态视图动画解决了问题:是
[self dismissViewControllerAnimated:YES completion:nil];
希望有帮助 我的解决方案包括Andrey Finayev的建议,但我还必须设置另一种过渡样式,否则在动画结束后我会出现空白屏幕
UIViewController *mVC = [[UIViewController alloc] init];
mVC.modalPresentationStyle = UIModalPresentationFullScreen;
mVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.navigationController presentViewController:mVC animated:NO completion:^{
[self.navigationController dismissViewControllerAnimated:YES completion:^{
}];
}];
为了防止mdonia解决方案中出现小的“闪烁”,我在后面添加了一个dispatch_,并能够使用动画关闭虚拟模态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:^{}];
});
}];
看起来当然仍然像一个丑陋的解决办法,但我没有找到一个更好的解决方案在给定的时间;(您从何处显示此仅lanscape的viewController?它是导航堆栈中的“推送”还是以模式显示的viewController?(在这种情况下更容易)是的,它是导航堆栈中的推送。我的根视图控制器是一个UITabBarViewController,每个项目都有一个UINavigationController。