pkluz / PKRevealController

PKRevealController is a delightful view controller container for iOS, enabling you to present multiple controllers on top of one another.
Other
3.85k stars 660 forks source link

Does it support a dim overlay on the fronViewController when the right/left controllers are focused ? #208

Open AdityaSethi opened 10 years ago

pbassut commented 9 years ago

+1. Issue almost one yr old. I guess that's a no.

pbassut commented 9 years ago

It's faily easy to do it, though. Do this in the frontViewController

    overlay = [[UIView alloc] initWithFrame:self.view.frame];
    [overlay setHidden:YES];
    [overlay setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:ALPHA_FRONTVC_OVERLAY]];
    [self.view addSubview:overlay];

    self.revealController.delegate = self;

Since, now, your ViewController gets all the events from the PKRevealing protocol, you do this:


- (void)revealController:(PKRevealController *)revealController willChangeToState:(PKRevealControllerState)state{
    if(state == PKRevealControllerShowsFrontViewController){
        [overlay setAlpha:ALPHA_FRONTVC_OVERLAY];

        [UIView animateWithDuration:.5 animations:^{
            overlay.alpha = 0;

        } completion:^(BOOL finished) {
            [overlay setHidden:YES];
        }];
    }else if(state == PKRevealControllerShowsLeftViewController){
        [overlay setAlpha:0];
        [overlay setHidden:NO];

        [UIView animateWithDuration:.5 animations:^{
            [overlay setAlpha:ALPHA_FRONTVC_OVERLAY];
        }];
    }
}

Where ALPHA_FRONTVC_OVERLAY is how dark you want the FrontViewController to get.

kokuneye commented 9 years ago

Nicely done. IMO, I found making the animation to overlay same as the PKReve.. animationDuration cool.

BorisNikolic commented 8 years ago

Thanks for the code!