1

我有两个视图控制器嵌入在导航控制器中,我的第一个视图控制器允许旋转,而我的第二个视图控制器应始终以纵向模式打开,例如,即使我在第一视图控制器中处于横向模式我想打开我的第二个人像,如何强制我的视图控制器始终以纵向模式打开

我通过先推动segue来呈现第二个视图控制器。

+0

的可能的复制[如何强制视图控制器留在肖像模式?](http://stackoverflow.com/questions/16720968/how-to -force-view-controller-to-stay-in-portrait-mode) –

+0

[如何在iOS 6中强制UIViewController以Portait方向](http://stackoverflow.com/questions/12520030/how-to -force-A-的UIViewController到波泰特方位用在-IOS-6) – kb920

回答

2

你将不得不实施shouldAutorotate第二VC

你目前的第二VC(纵向)就在调用

if([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) { 
     [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:@"orientation"]; 
} 
0

解决方案1:创建一个自定义的UINavigationController子类,并重写这些方法这样的:

@interface LockedNavigationViewController() 

@end 

@implementation LockedNavigationViewController 

-(BOOL)shouldAutorotate { 
    return UIInterfaceOrientationMaskPortrait; 
} 

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000 
- (NSUInteger)supportedInterfaceOrientations 
#else 
- (UIInterfaceOrientationMask)supportedInterfaceOrientations 
#endif 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 
    return UIInterfaceOrientationPortrait; 
} 

@end 
0

enter image description here

选择您的项目 - >一般,然后按照上面的图片。

1

可以在乌尔AppDelegate类使用此方法,并与布尔VAR

-(NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { 
    if(self.isDisplayInPoratrait){ 
     return UIInterfaceOrientationMaskPortrait; 
    else 
     // return ur required orientation 
} 

self.isDisplayInPoratrait保持在AppDelagate集类这个变量是其中U想呈现在肖像声明布尔变量。放置在类此方法其中U湾呈现在肖像

-(BOOL)shouldAutorotate { 
    return NO; 
} 

-(UIInterfaceOrientationMask)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskPortrait; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 
    return UIInterfaceOrientationLandscapeLeft; 
} 
相关问题