From c3df5be14ba385e8bc8cd58af0496118b40b8ca8 Mon Sep 17 00:00:00 2001 From: Philippe Converset Date: Mon, 12 May 2014 17:00:42 +0200 Subject: [PATCH 1/2] Ability to show the menu from the navigation bar with an X offset and a width smaller than the screen width. --- REMenu/REMenu.h | 1 + REMenu/REMenu.m | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/REMenu/REMenu.h b/REMenu/REMenu.h index 22c4343..ea83fe5 100644 --- a/REMenu/REMenu.h +++ b/REMenu/REMenu.h @@ -105,6 +105,7 @@ typedef NS_ENUM(NSInteger, REMenuLiveBackgroundStyle) { - (void)showFromRect:(CGRect)rect inView:(UIView *)view; - (void)showInView:(UIView *)view; - (void)showFromNavigationController:(UINavigationController *)navigationController; +- (void)showFromNavigationController:(UINavigationController *)navigationController offsetX:(CGFloat)offsetX width:(CGFloat)width; - (void)setNeedsLayout; - (void)closeWithCompletion:(void (^)(void))completion; - (void)close; diff --git a/REMenu/REMenu.m b/REMenu/REMenu.m index abf651b..1b8f4c2 100644 --- a/REMenu/REMenu.m +++ b/REMenu/REMenu.m @@ -291,18 +291,28 @@ - (void)showInView:(UIView *)view } - (void)showFromNavigationController:(UINavigationController *)navigationController +{ + [self showFromNavigationController:navigationController offsetX:0 width:navigationController.navigationBar.frame.size.width]; +} + +- (void)showFromNavigationController:(UINavigationController *)navigationController offsetX:(CGFloat)offsetX width:(CGFloat)width { if (self.isAnimating) { return; } self.navigationBar = navigationController.navigationBar; - [self showFromRect:CGRectMake(0, 0, navigationController.navigationBar.frame.size.width, navigationController.view.frame.size.height) inView:navigationController.view]; + [self showFromRect:CGRectMake(offsetX, 0, width, navigationController.view.frame.size.height) inView:navigationController.view]; self.containerView.appearsBehindNavigationBar = self.appearsBehindNavigationBar; self.containerView.navigationBar = navigationController.navigationBar; if (self.appearsBehindNavigationBar) { [navigationController.view bringSubviewToFront:navigationController.navigationBar]; } + + if(width != navigationController.navigationBar.frame.size.width) + { + self.containerView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin; + } } - (void)closeWithCompletion:(void (^)(void))completion From 1c559667e6ecf6275a28b5fd0a41626f3fef45c7 Mon Sep 17 00:00:00 2001 From: Philippe Converset Date: Mon, 12 May 2014 18:38:41 +0200 Subject: [PATCH 2/2] Fix layout issue on orientation change. --- REMenu/REMenu.h | 1 + REMenu/REMenu.m | 35 +++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/REMenu/REMenu.h b/REMenu/REMenu.h index ea83fe5..e89a6e9 100644 --- a/REMenu/REMenu.h +++ b/REMenu/REMenu.h @@ -103,6 +103,7 @@ typedef NS_ENUM(NSInteger, REMenuLiveBackgroundStyle) { - (id)initWithItems:(NSArray *)items; - (void)showFromRect:(CGRect)rect inView:(UIView *)view; +- (void)showFromRect:(CGRect)rect inView:(UIView *)view offsetX:(CGFloat)offsetX width:(CGFloat)width; - (void)showInView:(UIView *)view; - (void)showFromNavigationController:(UINavigationController *)navigationController; - (void)showFromNavigationController:(UINavigationController *)navigationController offsetX:(CGFloat)offsetX width:(CGFloat)width; diff --git a/REMenu/REMenu.m b/REMenu/REMenu.m index 1b8f4c2..dbc59ac 100644 --- a/REMenu/REMenu.m +++ b/REMenu/REMenu.m @@ -107,6 +107,11 @@ - (id)initWithItems:(NSArray *)items } - (void)showFromRect:(CGRect)rect inView:(UIView *)view +{ + [self showFromRect:rect inView:view offsetX:0 width:rect.size.width]; +} + +- (void)showFromRect:(CGRect)rect inView:(UIView *)view offsetX:(CGFloat)offsetX width:(CGFloat)width { if (self.isAnimating) { return; @@ -220,7 +225,18 @@ - (void)showFromRect:(CGRect)rect inView:(UIView *)view // Set up frames // - self.menuWrapperView.frame = CGRectMake(0, -self.combinedHeight - navigationBarOffset, rect.size.width, self.combinedHeight + navigationBarOffset); + self.menuWrapperView.frame = CGRectMake(offsetX, -self.combinedHeight - navigationBarOffset, width, self.combinedHeight + navigationBarOffset); + if(width != rect.size.width) + { + if(self.menuWrapperView.center.x < rect.size.width/2) + { + self.menuWrapperView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin; + } + else + { + self.menuWrapperView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; + } + } self.menuView.frame = self.menuWrapperView.bounds; if (REUIKitIsFlatMode() && self.liveBlur) { self.toolbar.frame = self.menuWrapperView.bounds; @@ -250,7 +266,7 @@ - (void)showFromRect:(CGRect)rect inView:(UIView *)view options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseInOut animations:^{ self.backgroundView.alpha = self.backgroundAlpha; - CGRect frame = self.menuView.frame; + CGRect frame = self.menuWrapperView.frame; frame.origin.y = -40.0 - self.separatorHeight; self.menuWrapperView.frame = frame; } completion:^(BOOL finished) { @@ -262,7 +278,7 @@ - (void)showFromRect:(CGRect)rect inView:(UIView *)view options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseInOut animations:^{ self.backgroundView.alpha = self.backgroundAlpha; - CGRect frame = self.menuView.frame; + CGRect frame = self.menuWrapperView.frame; frame.origin.y = -40.0 - self.separatorHeight; self.menuWrapperView.frame = frame; } completion:^(BOOL finished) { @@ -276,7 +292,7 @@ - (void)showFromRect:(CGRect)rect inView:(UIView *)view options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseInOut animations:^{ self.backgroundView.alpha = self.backgroundAlpha; - CGRect frame = self.menuView.frame; + CGRect frame = self.menuWrapperView.frame; frame.origin.y = -40.0 - self.separatorHeight; self.menuWrapperView.frame = frame; } completion:^(BOOL finished) { @@ -302,17 +318,12 @@ - (void)showFromNavigationController:(UINavigationController *)navigationControl } self.navigationBar = navigationController.navigationBar; - [self showFromRect:CGRectMake(offsetX, 0, width, navigationController.view.frame.size.height) inView:navigationController.view]; + [self showFromRect:CGRectMake(0, 0, navigationController.navigationBar.frame.size.width, navigationController.view.frame.size.height) inView:navigationController.view offsetX:offsetX width:width]; self.containerView.appearsBehindNavigationBar = self.appearsBehindNavigationBar; self.containerView.navigationBar = navigationController.navigationBar; if (self.appearsBehindNavigationBar) { [navigationController.view bringSubviewToFront:navigationController.navigationBar]; } - - if(width != navigationController.navigationBar.frame.size.width) - { - self.containerView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin; - } } - (void)closeWithCompletion:(void (^)(void))completion @@ -328,7 +339,7 @@ - (void)closeWithCompletion:(void (^)(void))completion delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseInOut animations:^ { - CGRect frame = self.menuView.frame; + CGRect frame = self.menuWrapperView.frame; frame.origin.y = - self.combinedHeight - navigationBarOffset; self.menuWrapperView.frame = frame; self.backgroundView.alpha = 0; @@ -359,7 +370,7 @@ - (void)closeWithCompletion:(void (^)(void))completion if (self.bounce) { [UIView animateWithDuration:self.bounceAnimationDuration animations:^{ - CGRect frame = self.menuView.frame; + CGRect frame = self.menuWrapperView.frame; frame.origin.y = -20.0; self.menuWrapperView.frame = frame; } completion:^(BOOL finished) {