Replacing UISplitViewController. New version isn't added for current orientation, frame size
Posted
by Justin Williams
on Stack Overflow
See other posts from Stack Overflow
or by Justin Williams
Published on 2010-05-24T18:00:09Z
Indexed on
2010/05/24
19:21 UTC
Read the original article
Hit count: 894
ipad
|uisplitviewcontroller
My application has two different modes I am switching between by replacing the two views in a UISplitViewController
. This involves instantiating the new views and a new UISplitViewController
. I then set the new detail view as the UISplitViewController's
delegate.
I'm running into an issue where when I replace the view controllers and splitview controller, they are not properly sized or added for the current orientation. For instance, if I have my iPad in UIDeviceOrientationPortraitUpsideDown
the view will be upside down when I call addSubview
, but will rotate to the proper orientation after a second. In another instance, if I have the device in landscape mode and swap the views, the detail view controller is not fully stretched to the size of the view. If I rotate the device to portrait and back to landscape, its resized properly.
The code I'm using to create the new split view and view controllers is as follows.
- (void)showNotes {
teiphoneAppDelegate *appDelegate = (teiphoneAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.splitViewController.view removeFromSuperview];
OMSavedScrapsController *notesViewController = [[OMSavedScrapsController alloc] initWithNibName:@"SavedScraps" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:notesViewController];
ComposeViewController *noteDetailViewController = [[ComposeViewController alloc] initWithNibName:@"ComposeView-iPad" bundle:nil];
UISplitViewController *newSplitVC = [[UISplitViewController alloc] init];
newSplitVC.viewControllers = [NSArray arrayWithObjects:navController, noteDetailViewController, nil];
newSplitVC.delegate = noteDetailViewController;
appDelegate.splitViewController = newSplitVC;
// Fade in the new split view
appDelegate.splitViewController.view.alpha = 0.0f;
[appDelegate.window addSubview:appDelegate.splitViewController.view];
[appDelegate.window makeKeyAndVisible];
[UIView beginAnimations:nil context:appDelegate.window];
[UIView setAnimationDuration: 0.5f];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
appDelegate.splitViewController.view.alpha = 1.0f;
[UIView commitAnimations];
[notesViewController release];
[navController release];
[noteDetailViewController release];
[newSplitVC release];
}
Any suggestions for how to get the new splitview to add for the device's current orientation and frame?
© Stack Overflow or respective owner