@@ -36,6 +36,7 @@ @interface SlideNavigationController()
3636
3737@implementation SlideNavigationController
3838
39+ #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO (v ) ([[[UIDevice currentDevice ] systemVersion ] compare: v options: NSNumericSearch] != NSOrderedAscending)
3940#define MENU_SLIDE_ANIMATION_DURATION .3
4041#define MENU_QUICK_SLIDE_ANIMATION_DURATION .18
4142#define MENU_IMAGE @" menu-button"
@@ -44,7 +45,8 @@ @implementation SlideNavigationController
4445#define MENU_DEFAULT_SLIDE_OFFSET 60
4546#define MENU_FAST_VELOCITY_FOR_SWIPE_FOLLOW_DIRECTION 1200
4647#define MENU_REVEAL_ANIMATION_DEFAULT_SLIDE_MOVEMENT 100
47- #define MENU_REVEAL_ANIMATION_DEFAULT_FADE_MAXIMUM_ALPHA .9
48+ #define MENU_REVEAL_ANIMATION_DEFAULT_FADE_MAXIMUM_ALPHA .7
49+ #define STATUS_BAR_HEIGHT 20
4850
4951static SlideNavigationController *singletonInstance;
5052
@@ -131,6 +133,11 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO
131133 CGRect rect = self.view .frame ;
132134 self.leftMenu .view .frame = rect;
133135 self.rightMenu .view .frame = rect;
136+
137+ // Move menus accordingly to avoid a weird animation during opening/closing menu after a rotation
138+ [self updateMenuAnimation: MenuLeft];
139+ [self updateMenuAnimation: MenuRight];
140+
134141 self.view .layer .shadowPath = [UIBezierPath bezierPathWithRect: self .view.bounds].CGPath ;
135142
136143 // we set shadowOpacity to 0 in willRotateToInterfaceOrientation, after the rotation we want to add the shadow back
@@ -177,6 +184,33 @@ - (void)switchToViewController:(UIViewController *)viewController withCompletion
177184 }
178185}
179186
187+ - (void )closeMenuWithCompletion : (void (^)())completion
188+ {
189+ [self closeMenuWithDuration: MENU_SLIDE_ANIMATION_DURATION andCompletion: completion];
190+ }
191+
192+ - (void )openMenu : (Menu)menu withCompletion : (void (^)())completion
193+ {
194+ [self openMenu: menu withDuration: MENU_SLIDE_ANIMATION_DURATION andCompletion: completion];
195+ }
196+
197+ - (void )toggleLeftMenu
198+ {
199+ [self toggleMenu: MenuLeft withCompletion: nil ];
200+ }
201+
202+ - (void )toggleRightMenu
203+ {
204+ [self toggleMenu: MenuRight withCompletion: nil ];
205+ }
206+
207+ - (BOOL )isMenuOpen
208+ {
209+ return (self.horizontalLocation == 0 ) ? NO : YES ;
210+ }
211+
212+ #pragma mark - Override Methods -
213+
180214- (NSArray *)popToRootViewControllerAnimated : (BOOL )animated
181215{
182216 if ([self isMenuOpen ])
@@ -225,6 +259,14 @@ - (NSArray *)popToViewController:(UIViewController *)viewController animated:(BO
225259
226260#pragma mark - Private Methods -
227261
262+ - (void )toggleMenu : (Menu)menu withCompletion : (void (^)())completion
263+ {
264+ if ([self isMenuOpen ])
265+ [self closeMenuWithCompletion: completion];
266+ else
267+ [self openMenu: menu withCompletion: completion];
268+ }
269+
228270- (UIBarButtonItem *)barButtonItemForMenu : (Menu)menu
229271{
230272 SEL selector = (menu == MenuLeft) ? @selector (leftMenuSelected: ) : @selector (righttMenuSelected: );
@@ -243,11 +285,6 @@ - (UIBarButtonItem *)barButtonItemForMenu:(Menu)menu
243285 }
244286}
245287
246- - (BOOL )isMenuOpen
247- {
248- return (self.horizontalLocation == 0 ) ? NO : YES ;
249- }
250-
251288- (BOOL )shouldDisplayMenu : (Menu)menu forViewController : (UIViewController *)vc
252289{
253290 if (menu == MenuRight)
@@ -291,11 +328,6 @@ - (void)openMenu:(Menu)menu withDuration:(float)duration andCompletion:(void (^)
291328 }];
292329}
293330
294- - (void )openMenu : (Menu)menu withCompletion : (void (^)())completion
295- {
296- [self openMenu: menu withDuration: MENU_SLIDE_ANIMATION_DURATION andCompletion: completion];
297- }
298-
299331- (void )closeMenuWithDuration : (float )duration andCompletion : (void (^)())completion
300332{
301333 [self .topViewController.view removeGestureRecognizer: self .tapRecognizer];
@@ -314,11 +346,6 @@ - (void)closeMenuWithDuration:(float)duration andCompletion:(void (^)())completi
314346 }];
315347}
316348
317- - (void )closeMenuWithCompletion : (void (^)())completion
318- {
319- [self closeMenuWithDuration: MENU_SLIDE_ANIMATION_DURATION andCompletion: completion];
320- }
321-
322349- (void )moveHorizontallyToLocation : (CGFloat)location
323350{
324351 CGRect rect = self.view .frame ;
@@ -353,6 +380,7 @@ - (void)updateMenuAnimation:(Menu)menu
353380
354381 if (self.menuRevealAnimation == MenuRevealAnimationFade || self.menuRevealAnimation == MenuRevealAnimationSlideAndFade)
355382 {
383+ self.menuRevealFadeAnimationView .frame = menuViewController.view .bounds ;
356384 [menuViewController.view addSubview: self .menuRevealFadeAnimationView];
357385 self.menuRevealFadeAnimationView .alpha = self.menuRevealAnimationFadeMaximumAlpha - (self.menuRevealAnimationFadeMaximumAlpha *progress);
358386 }
@@ -370,14 +398,29 @@ - (void)updateMenuAnimation:(Menu)menu
370398 location = (location < 0 ) ? 0 : location;
371399
372400 CGRect rect = menuViewController.view .frame ;
401+ BOOL isIos7 = SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO (@" 7.0" );
373402
374403 if (UIInterfaceOrientationIsLandscape (self.interfaceOrientation ))
375404 {
376405 rect.origin .y = (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) ? location : location*-1 ;
406+
407+ if (!isIos7)
408+ {
409+ // For some reasons in landscape belos the status bar is considered y=0, but in portrait it's considered y=20
410+ rect.origin .x = (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) ? 0 : STATUS_BAR_HEIGHT;
411+ rect.size .width = self.view .frame .size .width -STATUS_BAR_HEIGHT;
412+ }
377413 }
378414 else
379415 {
380416 rect.origin .x = (self.interfaceOrientation == UIInterfaceOrientationPortrait) ? location : location*-1 ;
417+
418+ if (!isIos7)
419+ {
420+ // For some reasons in landscape belos the status bar is considered y=0, but in portrait it's considered y=20
421+ rect.origin .y = (self.interfaceOrientation == UIInterfaceOrientationPortrait) ? STATUS_BAR_HEIGHT : 0 ;
422+ rect.size .height = self.view .frame .size .height -STATUS_BAR_HEIGHT;
423+ }
381424 }
382425
383426 menuViewController.view .frame = rect;
@@ -395,7 +438,7 @@ - (void)prepareMenuForReveal:(Menu)menu
395438
396439 if (self.menuRevealAnimation == MenuRevealAnimationFade || self.menuRevealAnimation == MenuRevealAnimationSlideAndFade)
397440 {
398- menuViewController. view .alpha = self.menuRevealAnimationFadeMaximumAlpha ;
441+ self. menuRevealFadeAnimationView .alpha = self.menuRevealAnimationFadeMaximumAlpha ;
399442 self.menuRevealFadeAnimationView .frame = menuViewController.view .bounds ;
400443 }
401444
@@ -644,7 +687,6 @@ - (UIView *)menuRevealFadeAnimationView
644687 if (!_menuRevealFadeAnimationView)
645688 {
646689 _menuRevealFadeAnimationView = [[UIView alloc ] init ];
647- _menuRevealFadeAnimationView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
648690 _menuRevealFadeAnimationView.backgroundColor = [UIColor blackColor ];
649691 _menuRevealFadeAnimationView.frame = self.view .bounds ;
650692 }
0 commit comments