@interface UIViewController (PPRevealSideViewController)

@property (nonatomic, retain) PPRevealSideViewController *revealSideViewController;

@end

@implementation UIViewController (PPRevealSideViewController)

static char revealSideViewControllerKey;

 

- (void) setRevealSideViewController:(PPRevealSideViewController *)revealSideViewController {

    [self willChangeValueForKey:@"revealSideViewController"];

    objc_setAssociatedObject( self

                             &revealSideViewControllerKey,

                             revealSideViewController,

                             OBJC_ASSOCIATION_RETAIN );

    [self didChangeValueForKey:@"revealSideViewController"];

}

 

- (PPRevealSideViewController*) revealSideViewController {

    id controller = objc_getAssociatedObject( self

                                             &revealSideViewControllerKey );

    

    // because we can't ask the navigation controller to set to the pushed controller the revealSideViewController !

    if (!controller && self.navigationController)

        controller = self.navigationController.revealSideViewController;

    

    if (!controller && self.tabBarController)

        controller = self.tabBarController.revealSideViewController;

    

    return controller;

}

 

@end

 

@interface UIView (PPRevealSideViewController)

@property (nonatomic, assign) UIEdgeInsets revealSideInset;

@end

@implementation UIView (PPRevealSideViewController)

static char revealSideInsetKey;

 

- (void) setRevealSideInset:(UIEdgeInsets)revealSideInset {

    [self willChangeValueForKey:@"revealSideInset"];

    NSString *stringInset = NSStringFromUIEdgeInsets(revealSideInset);

    objc_setAssociatedObject( self

                             &revealSideInsetKey,

                             stringInset,

                             OBJC_ASSOCIATION_RETAIN );

    [self didChangeValueForKey:@"revealSideInset"];

}

 

- (UIEdgeInsets) revealSideInset {

    NSString *stringInset =  objc_getAssociatedObject( self

                                                      &revealSideInsetKey );

    UIEdgeInsets inset = UIEdgeInsetsZero;

    if (stringInset)

        inset = UIEdgeInsetsFromString(stringInset);

    else

        inset = self.superview.revealSideInset;

    return inset;

}

 

@end