2016-10-24 3 views
0

Мой UIViewController не называется методом shouldAutorotate.
попробовал несколько способов для сильного отображения ВК в портретном режиме.
shouldAutorotate Не вызывается - [Не используется раскадровка]

Пример кода ниже:

AppDelegate.m

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
self.window.backgroundColor = [UIColor whiteColor]; 
self.navController = [[UINavigationController alloc] initWithRootViewController:[[VCLogin alloc] init]]; 
[self.window setRootViewController:self.navController]; 
[UIApplication sharedApplication].statusBarHidden = YES; 
[self.window makeKeyAndVisible]; 

VCLogin.m

- (BOOL)shouldAutorotate 
{ 
    return [self.navigationController.visibleViewController shouldAutorotate]; 
} 

- (UIInterfaceOrientationMask)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationPortraitUpsideDown; 
} 

и включен Ориентация устройства, как 'Портрет', «Пейзаж Left 'и' Landscape Right '

Любая идея будет оценена по достоинству.
Спасибо заранее.

+0

Вам необходимо защитить определенный vc, чтобы быть в портретном режиме? – vaibhav

+0

Да. Я использую iOS 10 sdk –

ответ

0

Я получил решение.

Добавлен пользовательский класс UINavigationController.

navigationControllerViewController.h

#import <UIKit/UIKit.h> 

@interface navigationControllerViewController : UINavigationController 

@end 

и переопределить следующие методы

navigationControllerViewController.m

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

- (UIInterfaceOrientationMask)supportedInterfaceOrientations { 
    return [self.visibleViewController supportedInterfaceOrientations]; 
} 

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

затем назначен этот пользовательская навигацию контроллер внутри AppDelegate.m F ile

// Replace 
self.navController = [[UINavigationController alloc] initWithRootViewController:[[VCMasterView alloc] init]]; 

// With 
self.navController = [[navigationControllerViewController alloc] initWithRootViewController:[[VCMasterView alloc] init]]; 
0

Попробуйте добавить следующий код:

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
return UIInterfaceOrientationMaskAllButUpsideDown; 
//or return UIInterfaceOrientationMaskPortrait , etc as your requirement 
} 
+0

на самом деле, я ищу для поддержки только одного vc в портретном режиме во всем приложении. –

+0

сделать этот viewcontroller в раскадровке с помощью sizeclass: компактная ширина и регулярная высота –

+0

К сожалению, мой проект не находится в раскадровке. Он хранит только файлы xib. –

Смежные вопросы