ViewDeck sizing of left UIViewController

1.8k Views Asked by At

I am using ViewDeck to power the sliding UI in my iPad app but i'm hitting a few problems.

I want to size the leftViewController to a specific size regardless of the rotation. The code I have to setup ViewDeck is as follows oh and i'm using storyboards.

        - (id)initWithCoder:(NSCoder *)aDecoder
    {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:@"leftViewController"];
        JWTimerGroupsViewController *timerGroupsViewController = navigationController.viewControllers[0];

        IISideController *constrainedSizeLeftViewController = [[IISideController alloc] initWithViewController:navigationController];

        JWMainTableViewController *middleViewController = (JWMainTableViewController *)[storyboard instantiateViewControllerWithIdentifier:@"middleViewController"];    
        [timerGroupsViewController setDelegate:middleViewController];
        self = [super initWithCenterViewController:middleViewController leftViewController:constrainedSizeLeftViewController];
        self.centerhiddenInteractivity = IIViewDeckCenterHiddenNotUserInteractiveWithTapToClose;

        /* This below IS NOT the size of the left view controller? Just seems odd that it isn't */
        [super setLeftSize:200];  
        [super setSizeMode:IIViewDeckViewSizeMode];

        if (self) {
            // Add any extra init code here
        }

        return self;
    }

The setLeftSize appears to set the topViewControllers width? Which then makes the left view controller size inconsistent when rotating.

Also I'm seeing some really terrible blocky shadows when the topVC is opened and then the device is rotated.

Is it possible to fix the size of the left ViewController and the amount the top VC opens in ViewDeck?

EDIT

I have just found a reference to this method:

    IISideController *constrainedSizeLeftViewController = [[IISideController alloc] initWithViewController:navigationController constrained:200];

Which DOES constrain the left viewcontroller to a specific value. But now there is still no way to have the top VC open to that width?!

1

There are 1 best solutions below

0
On

You could try the approach suggested here: https://stackoverflow.com/a/16484446/928209

Basically it is:

  1. instantiate your IIViewDeckController in code (not from the storyboard)
  2. set the center view of the view deck controller to the rootViewController from your storyboard and side views to whatever you need.
  3. set the rootViewController of your app to the view deck controller.

Here is my code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{   
    UIStoryboard* storyboard = self.window.rootViewController.storyboard; 

    UINavigationController* leftSideVC = (UINavigationController*)[storyboard instantiateViewControllerWithIdentifier:@"tableNavController"];
    UINavigationController* centerNavVC = (UINavigationController*) self.window.rootViewController;

    IIViewDeckController* viewDeckController =  [[IIViewDeckController alloc] initWithCenterViewController:centerNavVC leftViewController:leftSideVC rightViewController:nil];
    self.window.rootViewController = viewDeckController;
    viewDeckController.resizesCenterView = YES;
    viewDeckController.sizeMode = IIViewDeckViewSizeMode;

    [self.window makeKeyAndVisible];
    return YES;
}

When I tried this approach coding in my IIViewDeckController after loading my storyboard, I found that a lot of my problems with view sizing went away. Before, for example, in order to make the side view a fixed width I had to set the leftSize property to (screenWidth - width) instead of the actual "width" I wanted. Once I made the IIViewDeckController the rootViewController of the app not via the storyboard but instead in code in my AppDelegate, I could set the fixed size to "width" and it worked properly.