我在导航控制器中嵌入了两个视图控制器,我的第一个视图控制器可以旋转,而我的第二个视图控制器应该始终以纵向模式打开,例如,即使我在第一个视图控制器中处于横向模式,我想要只用肖像打开我的第二个,
我通过从第一个推送segue来呈现第二个视图控制器。
答案 0 :(得分:2)
您必须在第二个VC上实施shouldAutorotate
在您出示第二个VC(肖像)电话之前
if([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) {
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:@"orientation"];
}
答案 1 :(得分:1)
您可以在您的AppDelegate Class中使用此方法,并使用bool var
进行维护-(NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if(self.isDisplayInPoratrait){
return UIInterfaceOrientationMaskPortrait;
else
// return ur required orientation
}
self.isDisplayInPoratrait
是在AppDelagate
中声明的bool变量,在类中设置此变量是,您希望以纵向形式呈现。把这个方法放在你要以肖像呈现的课上
-(BOOL)shouldAutorotate {
return NO;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeLeft;
}
答案 2 :(得分: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
答案 3 :(得分:0)