2013-09-23 32 views
2

我有以下控制器,(在iPad上我选择了所有类型的方向性模式)力控制器改变自己的方向在纵向或横向

这里是我的iPad故事板布局

Custom NavigationController > Loading Ctrl > Main Controller. 

我的自定义导航包含

-(BOOL)shouldAutorotate 
{ 
    return [[self.viewControllers lastObject] shouldAutorotate]; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return [[self.viewControllers lastObject] supportedInterfaceOrientations]; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; 
} 

在我载入控制器

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) 
     return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; 
    else 
     return UIInterfaceOrientationMaskPortrait; 
} 

的supportedInterfaceOrientations被称为像往常一样,一切似乎确定,但是当我使用performSegue

-(NSUInteger)supportedInterfaceOrientations 
{ 
    if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) 
     return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; 
    else 
     return UIInterfaceOrientationMaskPortrait; 
} 

在MainController没有更多的电话把我的主控制器。这是为什么?

+0

这个工作对我来说:http://stackoverflow.com/questions/22491786/force-landscape-viewcontroller-in-ios-7/22491787#22491787 –

回答

3

有一招。

从应用程序中获取状态栏并旋转它。

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES]; 

以模态方式创建和显示并关闭空视图控制器。

UIViewController *mVC = [[UIViewController alloc] init]; 
[self presentModalViewController:mVC animated:NO]; 
[self dismissModalViewControllerAnimated:NO]; 

现在您的设备已经被迫旋转。您现在可以继续使用正确的视图控制器,或使用导航控制器按下一个控制器。

+0

是不是有帮助? –

+0

然而,这工作,但它使用不推荐使用的函数(提出和解雇) – Jeef

+0

是的,他们被iOS 6取代,并被'presentViewController:animated:completion:'和'willismissViewControllerAnimated:completion:'取代。我还没有尝试他们是否工作。如果你试试看,我会很感激你的反馈。 –

1
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ 
return (interfaceOrientation == UIInterfaceOrientationPortrait);//choose portrait or landscape 
} 
- (BOOL) shouldAutorotate{ 
return NO; 
} 
- (NSUInteger) supportedInterfaceOrientations{ 
return UIInterfaceOrientationMaskPortrait;//choose portrait or landscape, same as above 
} 
+0

THNX!是最好的解决方案! – Lito

+0

@ n00bProgrammer哪个方法需要调用 - (void)viewWillAppear:(BOOL)animated – Muju