0

The documentation mentions adding shadows to the controller being animated to show the slide menu. However, instead of a shadow I would like to make the animated view controller to be darker. Is this possible?

Grzegorz Adam Hankiewicz
  • 7,349
  • 1
  • 36
  • 78

1 Answers1

1

I simply created a masking view and presented/removed it on notifications from the slidingviewcontroller. Added some nice fade in and fade out action for effect :) Hope this helps

#import <UIKit/UIKit.h>
UIView *overLayView;
@interface MyViewController : UIViewController {
    UIView *overLayView;
}
@end

@implementation MyViewController
- (void)viewDidLoad
{
    [super viewDidLoad];

    overLayView  = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    overLayView.backgroundColor = [UIColor blackColor];
}
-(void) viewWillAppear:(BOOL)animated{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(disableView) name:ECSlidingViewUnderLeftWillAppear object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enableView) name:ECSlidingViewTopWillReset object:nil];
}
- (void)viewWillDisappear:(BOOL)animated{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:ECSlidingViewUnderLeftWillAppear object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:ECSlidingViewTopWillReset object:nil];
}

-(void) disableView {

    overLayView.alpha = 0;

    [self.view addSubview:overLayView];

    [UIView animateWithDuration:0.5 animations:^{
        overLayView.alpha += kViewHelperUIViewMaskAlpha;
    }];
}

-(void) enableView {
    [UIView animateWithDuration:0.5 animations:^{
        overLayView.alpha -= kViewHelperUIViewMaskAlpha;

    } completion:^(BOOL fin){
        if(fin){
            [overLayView removeFromSuperview];
        }
    }];
}

@end
Royston Yinkore
  • 561
  • 1
  • 8
  • 22
  • Looks like those notifications were removed in recent versions of the control but I can recover them from github history and use them. Thanks. – Grzegorz Adam Hankiewicz Sep 21 '14 at 17:13
  • 2 more things to know. 1. There's no notification posted in the current version(2) of ECSlidingViewController. You have to subclass [ECSlidingViewController completeTransition]; 2. I personally made a subclass of UIVIewController containing your implementation, for it looks cleaner. – addlistener May 28 '15 at 06:19