我有这个设置只支持大多数viewcontrollers中的横向
我的应用代表有这段代码:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
NSUInteger orientations = UIInterfaceOrientationMaskLandscape;
if (self.window.rootViewController) {
UIViewController * pressented = [[((UINavigationController *)self.window.rootViewController) viewControllers] lastObject];
orientations =[pressented supportedInterfaceOrientations];
}
return orientations;
}
在大多数viewcontrollers中:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
当我按下THIS控制器(我要旋转的控制器)时出现了问题:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskALL;
}
它完全旋转但是当我弹出viewcontroller(点击导航栏的后退按钮)时,方向为纵向,呈现的viewcontroller也将它的方向设置为Portrait。
如何使呈现视图控制器保持锁定在横向上,或强制有问题的控制器在弹出之前旋转回横向。
答案 0 :(得分:1)
将此添加到您的纵向视图控制器:
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
UIViewController* dummyController = [[UIViewController alloc] init];
[self presentViewController:dummyController animated:NO completion:^{
[self dismissViewControllerAnimated:NO completion:nil];
}];
}
我知道这是一个黑客,但它确实有效。谁知道更好的解决方案?