Skip to content

Starting with an opened sideview

Inferis edited this page Apr 18, 2013 · 3 revisions

If you want to have a sideview open when the view loads, just add the call in viewWillAppear and not in viewDidLoad:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    ... your stuff ...

    [self.viewDeckController openLeftViewAnimated:NO];
}

Setting animated to NO will cause the view to be opened immediately.

You need to call this in viewDidAppear since ViewDeck does a lot of initialization in viewWillAppear and not in viewDidLoad. If you need to do this only the first time a view loads, just add a boolean value in your controller to check if you've already opened the side view.

@implementation FooViewController {
    BOOL _openedSide;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    if (!_openedSide) {
        [self.viewDeckController openLeftViewAnimated:NO];
        _openedSide = YES;
    }
}

Animating a 'close sideview' when the view appears

Sometimes you want to have the sideview open already, and have it animate shut as a hint to the user. You can't have both animations in viewWillAppear because the close animation will occur as the view appears, and so it doesn't really show.

So what you do then is call closeLeftViewAnimated: in viewDidAppear:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.viewDeckController closeLeftViewAnimated:YES];
}

You'd also need the open call from the preceding chapter to have it actually open, of course.

This will cause the sideview to close once the view has appeared, and it will be properly visible and animating to the user now.

Clone this wiki locally