Мой UIViewController не вызвал метод shouldAutorotate.
попробовал несколько способов принудительно отобразить VC в портретном режиме.

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

< Сильный > 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;
}

И включил ориентацию устройства как «Книжная», «Альбомная влево» и «Альбомная вправо»

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

0
Shinurag KR 24 Окт 2016 в 16:40

2 ответа

Лучший ответ

Я нашел решение.

Добавлен собственный класс 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

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

// With
self.navController = [[navigationControllerViewController alloc] initWithRootViewController:[[VCMasterView alloc] init]];
0
Shinurag KR 30 Окт 2016 в 06:35

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

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskAllButUpsideDown;
//or return UIInterfaceOrientationMaskPortrait , etc as your requirement
}
0
Hrishikesh Menon 24 Окт 2016 в 13:55