Справочная информация и цель: у меня есть приложение для iPad на основе UISplitViewController - до сих пор оно поддерживало 4 ориентации, но теперь я хочу ограничить его только пейзажем.
Я изменил shouldAutorotateToInterfaceOrientation
левого контроллера вида, чтобы он поддерживал только альбомный режим, но это мешает viewWillAppear
вызываться.
Детали: контроллеры представления моего iPad организованы следующим образом:
window
`-- splitVC (UISplitViewController)
`-- rootNav (UINavigationController)
`-- hvc (HostManagerViewController, derived from UIViewController)
`-- detailViewController (DetailViewController, derived from UIViewController)
Это реализовано в делегате приложения, как показано ниже:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
HostManagerViewController *hvc = [[[HostManagerViewController alloc]
initWithNibName:nil bundle:nil] autorelease];
self.detailViewController = [[[DetailViewController alloc]
initWithNibName:nil bundle:nil] autorelease];
UINavigationController *rootNav = [[[UINavigationController alloc]
initWithRootViewController:hvc] autorelease];
UISplitViewController *splitVC= [[[UISplitViewController alloc] init] autorelease];
[splitVC setViewControllers:[NSArray arrayWithObjects:rootNav,
detailViewController, nil]];
splitVC.delegate = detailViewController;
[window addSubview:splitVC.view];
[window setRootViewController:splitVC];
return YES;
}
viewWillAppear
вызывается, когда оба DetailViewController.m
и HostManagerViewController.m
содержат
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Console output:
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 3
Hostmanager: Viewdidload
Should rotate called to hostmanager with 1
Hostmanager: viewwillappear
Но когда я меняю код HostManagerViewController
на
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (UIInterfaceOrientationIsLandscape(interfaceOrientation));
}
тогда 'viewWillAppear` HostManagerViewController не вызывается. Консольный вывод
Should rotate called to hostmanager with 1 (1 is the numeric value of interfaceOrientation)
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 3
Should rotate called to hostmanager with 3
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 3
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 3
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 3
Hostmanager: Viewdidload
Should rotate called to hostmanager with 1
В Info.plist поддерживаются только ландшафтные режимы
EDIT: вставлены сообщения NSLog для отслеживания shouldAutorotateToInterfaceOrientation
, viewWillAppear
и ViewDidLoad