Мой 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;
}
И включил ориентацию устройства как «Книжная», «Альбомная влево» и «Альбомная вправо»
Любая идея будет оценена по достоинству.
Заранее спасибо.
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]];
Попробуйте добавить следующий код:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskAllButUpsideDown;
//or return UIInterfaceOrientationMaskPortrait , etc as your requirement
}
Похожие вопросы
Новые вопросы
ios
iOS - мобильная операционная система, работающая на Apple iPhone, iPod touch и iPad. Используйте этот тег [ios] для вопросов, связанных с программированием на платформе iOS. Используйте связанные теги [target-c] и [swift] для проблем, характерных для этих языков программирования.