Laden Sie verschiedene xib-Dateien unter Orientierung in iOS
Ich habe zwei geschaffen.xib
Datei eins für Hochformat und andere für Querformat,
bei jeder umdrehung möchte ich jeweils laden.xib
Datei,
Hier ist mein Code-Schnipsel,
ViewAppDelegate.m-Klasse
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
if ([UIApplication sharedApplication].statusBarOrientation==UIInterfaceOrientationPortrait | [UIApplication sharedApplication].statusBarOrientation==UIInterfaceOrientationPortraitUpsideDown)
{
self.viewController = [[OrientationViewController alloc] initWithNibName:@"PortraitController" bundle:nil];
UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navigationController;
}
else{
self.viewController = [[OrientationViewController alloc] initWithNibName:@"LandscapeController" bundle:nil];
UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navigationController;
}
[self.window makeKeyAndVisible];
return YES;
}
ViewController.m-Klasse
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return YES;
}
-(void)viewWillLayoutSubviews{
if ([UIApplication sharedApplication].statusBarOrientation==UIInterfaceOrientationPortrait | [UIApplication sharedApplication].statusBarOrientation==UIInterfaceOrientationPortraitUpsideDown)
{
[[NSBundle mainBundle] loadNibNamed:@"PortraitController" owner:self options:nil];
}
else{
[[NSBundle mainBundle] loadNibNamed:@"LandscapeController" owner:self options:nil];
}
}
Nachdem ich so viel Code geschrieben habe, zeigt meine App nichts. Sie zeigt nur schwarzen Bildschirm.
Bitte schlagen Sie eine Lösung vor.