@@ -34,19 +34,12 @@ @interface SlideNavigationController()
3434@end
3535
3636@implementation SlideNavigationController
37- @synthesize righMenu;
38- @synthesize leftMenu;
39- @synthesize tapRecognizer;
40- @synthesize panRecognizer;
41- @synthesize draggingPoint;
42- @synthesize leftbarButtonItem;
43- @synthesize rightBarButtonItem;
44- @synthesize enableSwipeGesture;
4537
4638#define MENU_OFFSET 60
4739#define MENU_SLIDE_ANIMATION_DURATION .3
4840#define MENU_QUICK_SLIDE_ANIMATION_DURATION .1
4941#define MENU_IMAGE @" menu-button"
42+ #define DegreesToRadians (degrees ) (degrees * M_PI / 180 )
5043
5144static SlideNavigationController *singletonInstance;
5245
@@ -95,6 +88,16 @@ - (void)setup
9588 self.view .layer .shouldRasterize = YES ;
9689 self.view .layer .rasterizationScale = [UIScreen mainScreen ].scale ;
9790
91+ [[NSNotificationCenter defaultCenter ] addObserverForName: UIApplicationDidChangeStatusBarFrameNotification
92+ object: nil
93+ queue: nil
94+ usingBlock: ^(NSNotification *note){
95+ UIInterfaceOrientation orientation = [[UIApplication sharedApplication ] statusBarOrientation ];
96+ // Do more resizing on menus
97+ [self .leftMenu.view setTransform: [self transformForOrientation: orientation]];
98+ [self .righMenu.view setTransform: [self transformForOrientation: orientation]];
99+ }];
100+
98101 [self setEnableSwipeGesture: YES ];
99102}
100103
@@ -116,7 +119,7 @@ - (void)switchToViewController:(UIViewController *)viewController withCompletion
116119 delay: 0
117120 options: UIViewAnimationOptionCurveEaseOut
118121 animations: ^{
119- rect. origin . x = (rect.origin .x > 0 ) ? rect.size .width : -1 *rect.size .width ;
122+ [ self moveHorizontallyToLocation: (rect.origin.x > 0 ) ? rect.size.width : -1 *rect.size.width] ;
120123 self.view .frame = rect;
121124 } completion: ^(BOOL finished) {
122125
@@ -207,7 +210,14 @@ - (UIBarButtonItem *)barButtonItemForMenu:(Menu)menu
207210
208211- (BOOL )isMenuOpen
209212{
210- return (self.view .frame .origin .x == 0 ) ? NO : YES ;
213+ if (UIInterfaceOrientationIsLandscape ([UIDevice currentDevice ].orientation ))
214+ {
215+ return (self.view .frame .origin .y == 0 ) ? NO : YES ;
216+ }
217+ else
218+ {
219+ return (self.view .frame .origin .x == 0 ) ? NO : YES ;
220+ }
211221}
212222
213223- (BOOL )shouldDisplayMenu : (Menu)menu forViewController : (UIViewController *)vc
@@ -253,7 +263,8 @@ - (void)openMenu:(Menu)menu withDuration:(float)duration andCompletion:(void (^)
253263 animations: ^{
254264 CGRect rect = self.view .frame ;
255265 rect.origin .x = (menu == MenuLeft) ? (rect.size .width - MENU_OFFSET) : ((rect.size .width - MENU_OFFSET )* -1 );
256- self.view .frame = rect;
266+ [self moveHorizontallyToLocation: rect.origin.x];
267+ // self.view.frame = rect;
257268 }
258269 completion: ^(BOOL finished) {
259270 if (completion)
@@ -276,7 +287,8 @@ - (void)closeMenuWithDuration:(float)duration andCompletion:(void (^)())completi
276287 animations: ^{
277288 CGRect rect = self.view .frame ;
278289 rect.origin .x = 0 ;
279- self.view .frame = rect;
290+ [self moveHorizontallyToLocation: rect.origin.x];
291+ // self.view.frame = rect;
280292 }
281293 completion: ^(BOOL finished) {
282294 if (completion)
@@ -289,6 +301,63 @@ - (void)closeMenuWithCompletion:(void (^)())completion
289301 [self closeMenuWithDuration: MENU_SLIDE_ANIMATION_DURATION andCompletion: completion];
290302}
291303
304+ - (CGAffineTransform)transformForOrientation : (UIInterfaceOrientation)orientation
305+ {
306+ switch (orientation)
307+ {
308+ case UIInterfaceOrientationLandscapeLeft:
309+ return CGAffineTransformMakeRotation (-DegreesToRadians (90 ));
310+
311+ case UIInterfaceOrientationLandscapeRight:
312+ return CGAffineTransformMakeRotation (DegreesToRadians (90 ));
313+
314+ case UIInterfaceOrientationPortraitUpsideDown:
315+ return CGAffineTransformMakeRotation (DegreesToRadians (180 ));
316+
317+ case UIInterfaceOrientationPortrait:
318+ default :
319+ return CGAffineTransformMakeRotation (DegreesToRadians (0 ));
320+ }
321+ }
322+
323+ - (void )moveHorizontallyToLocation : (CGFloat)location
324+ {
325+ CGRect rect = self.view .frame ;
326+ UIInterfaceOrientation orientation = [UIDevice currentDevice ].orientation ;
327+
328+ if (UIInterfaceOrientationIsLandscape (orientation))
329+ {
330+ rect.origin .x = 0 ;
331+ rect.origin .y = (orientation == UIInterfaceOrientationLandscapeRight) ? location : location*-1 ;
332+ }
333+ else
334+ {
335+ rect.origin .x = (orientation == UIInterfaceOrientationPortrait) ? location : location*-1 ;
336+ rect.origin .y = 0 ;
337+ }
338+
339+ self.view .frame = rect;
340+ }
341+
342+ - (CGFloat)horizontalLocation
343+ {
344+ CGRect rect = self.view .frame ;
345+ UIInterfaceOrientation orientation = [UIDevice currentDevice ].orientation ;
346+
347+ if (UIInterfaceOrientationIsLandscape (orientation))
348+ {
349+ return (orientation == UIInterfaceOrientationLandscapeRight)
350+ ? rect.origin .y
351+ : rect.origin .y *-1 ;
352+ }
353+ else
354+ {
355+ return (orientation == UIInterfaceOrientationPortrait)
356+ ? rect.origin .x
357+ : rect.origin .x *-1 ;
358+ }
359+ }
360+
292361#pragma mark - UINavigationControllerDelegate Methods -
293362
294363- (void )navigationController : (UINavigationController *)navigationController
@@ -342,15 +411,16 @@ - (void)panDetected:(UIPanGestureRecognizer *)aPanRecognizer
342411 else if (aPanRecognizer.state == UIGestureRecognizerStateChanged)
343412 {
344413 NSInteger movement = translation.x - self.draggingPoint .x ;
345- CGRect rect = self. view . frame ;
346- rect. origin . x += movement;
414+ NSInteger newHorizontalLocation = [ self horizontalLocation ] ;
415+ newHorizontalLocation += movement;
347416
348- if (rect.origin .x >= self.minXForDragging && rect.origin .x <= self.maxXForDragging )
349- self.view .frame = rect;
417+ if (newHorizontalLocation >= self.minXForDragging && newHorizontalLocation <= self.maxXForDragging )
418+ [self moveHorizontallyToLocation: newHorizontalLocation];
419+ // self.view.frame = rect;
350420
351421 self.draggingPoint = translation;
352422
353- if (rect. origin . x > 0 )
423+ if (newHorizontalLocation > 0 )
354424 {
355425 [self .righMenu.view removeFromSuperview ];
356426 [self .view.window insertSubview: self .leftMenu.view atIndex: 0 ];
@@ -363,7 +433,7 @@ - (void)panDetected:(UIPanGestureRecognizer *)aPanRecognizer
363433 }
364434 else if (aPanRecognizer.state == UIGestureRecognizerStateEnded)
365435 {
366- NSInteger currentX = self. view . frame . origin . x ;
436+ NSInteger currentX = [ self horizontalLocation ] ;
367437 NSInteger currentXOffset = (currentX > 0 ) ? currentX : currentX * -1 ;
368438 NSInteger positiveVelocity = (velocity.x > 0 ) ? velocity.x : velocity.x * -1 ;
369439
@@ -432,29 +502,29 @@ - (NSInteger)maxXForDragging
432502
433503- (UITapGestureRecognizer *)tapRecognizer
434504{
435- if (!tapRecognizer )
505+ if (!_tapRecognizer )
436506 {
437- tapRecognizer = [[UITapGestureRecognizer alloc ] initWithTarget: self action: @selector (tapDetected: )];
507+ _tapRecognizer = [[UITapGestureRecognizer alloc ] initWithTarget: self action: @selector (tapDetected: )];
438508 }
439509
440- return tapRecognizer ;
510+ return _tapRecognizer ;
441511}
442512
443513- (UIPanGestureRecognizer *)panRecognizer
444514{
445- if (!panRecognizer )
515+ if (!_panRecognizer )
446516 {
447- panRecognizer = [[UIPanGestureRecognizer alloc ] initWithTarget: self action: @selector (panDetected: )];
517+ _panRecognizer = [[UIPanGestureRecognizer alloc ] initWithTarget: self action: @selector (panDetected: )];
448518 }
449519
450- return panRecognizer ;
520+ return _panRecognizer ;
451521}
452522
453523- (void )setEnableSwipeGesture : (BOOL )markEnableSwipeGesture
454524{
455- enableSwipeGesture = markEnableSwipeGesture;
525+ _enableSwipeGesture = markEnableSwipeGesture;
456526
457- if (enableSwipeGesture )
527+ if (_enableSwipeGesture )
458528 {
459529 [self .view addGestureRecognizer: self .panRecognizer];
460530 }
0 commit comments