From e5790197a30bd2d9b827065b705817420d6e6877 Mon Sep 17 00:00:00 2001 From: Aryan Ghassemi Date: Sun, 5 Jan 2014 10:07:46 -0800 Subject: [PATCH] - Overriding layoutSubviews and resizing left and right menus accordingly --- SlideMenu/Source/SlideNavigationController.m | 71 +++++++++----------- 1 file changed, 30 insertions(+), 41 deletions(-) diff --git a/SlideMenu/Source/SlideNavigationController.m b/SlideMenu/Source/SlideNavigationController.m index f02e84d..aef4fdb 100644 --- a/SlideMenu/Source/SlideNavigationController.m +++ b/SlideMenu/Source/SlideNavigationController.m @@ -50,14 +50,9 @@ static SlideNavigationController *singletonInstance; return singletonInstance; } -- (void)awakeFromNib +- (id)init { - [self setup]; -} - -- (id)initWithRootViewController:(UIViewController *)rootViewController -{ - if (self = [super initWithRootViewController:rootViewController]) + if (self = [super init]) { [self setup]; } @@ -65,9 +60,19 @@ static SlideNavigationController *singletonInstance; return self; } -- (id)init +- (id)initWithCoder:(NSCoder *)aDecoder { - if (self = [super init]) + if (self = [super initWithCoder:aDecoder]) + { + [self setup]; + } + + return self; +} + +- (id)initWithRootViewController:(UIViewController *)rootViewController +{ + if (self = [super initWithRootViewController:rootViewController]) { [self setup]; } @@ -88,19 +93,22 @@ static SlideNavigationController *singletonInstance; self.view.layer.shouldRasterize = YES; self.view.layer.rasterizationScale = [UIScreen mainScreen].scale; - [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidChangeStatusBarFrameNotification - object:nil - queue:nil - usingBlock:^(NSNotification *note){ - UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; - // Do more resizing on menus - [self.leftMenu.view setTransform:[self transformForOrientation:orientation]]; - [self.righMenu.view setTransform:[self transformForOrientation:orientation]]; - }]; - [self setEnableSwipeGesture:YES]; } +- (void)viewWillLayoutSubviews +{ + [super viewWillLayoutSubviews]; + + CGAffineTransform transform = self.view.transform; + self.leftMenu.view.transform = transform; + self.righMenu.view.transform = transform; + + CGRect rect = self.view.frame; + self.leftMenu.view.frame = rect; + self.righMenu.view.frame = rect; +} + #pragma mark - Public Methods - - (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion @@ -210,7 +218,7 @@ static SlideNavigationController *singletonInstance; - (BOOL)isMenuOpen { - if (UIInterfaceOrientationIsLandscape([UIDevice currentDevice].orientation)) + if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) { return (self.view.frame.origin.y == 0) ? NO : YES; } @@ -301,29 +309,10 @@ static SlideNavigationController *singletonInstance; [self closeMenuWithDuration:MENU_SLIDE_ANIMATION_DURATION andCompletion:completion]; } -- (CGAffineTransform)transformForOrientation:(UIInterfaceOrientation)orientation -{ - switch (orientation) - { - case UIInterfaceOrientationLandscapeLeft: - return CGAffineTransformMakeRotation(-DegreesToRadians(90)); - - case UIInterfaceOrientationLandscapeRight: - return CGAffineTransformMakeRotation(DegreesToRadians(90)); - - case UIInterfaceOrientationPortraitUpsideDown: - return CGAffineTransformMakeRotation(DegreesToRadians(180)); - - case UIInterfaceOrientationPortrait: - default: - return CGAffineTransformMakeRotation(DegreesToRadians(0)); - } -} - - (void)moveHorizontallyToLocation:(CGFloat)location { CGRect rect = self.view.frame; - UIInterfaceOrientation orientation = [UIDevice currentDevice].orientation; + UIInterfaceOrientation orientation = self.interfaceOrientation; if (UIInterfaceOrientationIsLandscape(orientation)) { @@ -342,7 +331,7 @@ static SlideNavigationController *singletonInstance; - (CGFloat)horizontalLocation { CGRect rect = self.view.frame; - UIInterfaceOrientation orientation = [UIDevice currentDevice].orientation; + UIInterfaceOrientation orientation = self.interfaceOrientation; if (UIInterfaceOrientationIsLandscape(orientation)) {