I have created two .xib
file one for portrait mode and other for landscape mode,
on each rotation i want to load respective .xib
file,
Here is my code snippet,
ViewAppDelegate.m class
- (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 class
- (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];
}
}
After writing this much of code my app shows nothing.. it shows only black screen.
please suggest some solution.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…