@@ -41,6 +41,7 @@ @implementation SlideNavigationController
4141#define MENU_SHADOW_RADIUS 10
4242#define MENU_SHADOW_OPACITY 1
4343#define MENU_DEFAULT_SLIDE_OFFSET 60
44+ #define MENU_FAST_VELOCITY_FOR_SWIPE_FOLLOW_DIRECTION 1000
4445
4546static SlideNavigationController *singletonInstance;
4647
@@ -112,12 +113,6 @@ - (void)viewWillLayoutSubviews
112113 self.rightMenu .view .frame = rect;
113114}
114115
115- - (void )viewDidLayoutSubviews
116- {
117- [super viewDidLayoutSubviews ];
118-
119- }
120-
121116- (void )willRotateToInterfaceOrientation : (UIInterfaceOrientation)toInterfaceOrientation duration : (NSTimeInterval )duration
122117{
123118 [super willRotateToInterfaceOrientation: toInterfaceOrientation duration: duration];
@@ -142,16 +137,15 @@ - (void)switchToViewController:(UIViewController *)viewController withCompletion
142137 return ;
143138 }
144139
145- __block CGRect rect = self.view .frame ;
146-
147140 if ([self isMenuOpen ])
148141 {
149142 [UIView animateWithDuration: MENU_SLIDE_ANIMATION_DURATION
150143 delay: 0
151144 options: UIViewAnimationOptionCurveEaseOut
152145 animations: ^{
153- [self moveHorizontallyToLocation: (rect.origin.x > 0 ) ? rect.size.width : -1 *rect.size.width];
154- self.view .frame = rect;
146+ CGFloat width = self.horizontalSize ;
147+ CGFloat moveLocation = (self.horizontalLocation > 0 ) ? width : -1 *width;
148+ [self moveHorizontallyToLocation: moveLocation];
155149 } completion: ^(BOOL finished) {
156150
157151 [super popToRootViewControllerAnimated: NO ];
@@ -241,14 +235,7 @@ - (UIBarButtonItem *)barButtonItemForMenu:(Menu)menu
241235
242236- (BOOL )isMenuOpen
243237{
244- if (UIInterfaceOrientationIsLandscape (self.interfaceOrientation ))
245- {
246- return (self.view .frame .origin .y == 0 ) ? NO : YES ;
247- }
248- else
249- {
250- return (self.view .frame .origin .x == 0 ) ? NO : YES ;
251- }
238+ return (self.horizontalLocation == 0 ) ? NO : YES ;
252239}
253240
254241- (BOOL )shouldDisplayMenu : (Menu)menu forViewController : (UIViewController *)vc
@@ -293,10 +280,9 @@ - (void)openMenu:(Menu)menu withDuration:(float)duration andCompletion:(void (^)
293280 options: UIViewAnimationOptionCurveEaseOut
294281 animations: ^{
295282 CGRect rect = self.view .frame ;
296- CGFloat width = ( UIInterfaceOrientationIsLandscape ( self.interfaceOrientation )) ? rect. size . height : rect. size . width ;
283+ CGFloat width = self.horizontalSize ;
297284 rect.origin .x = (menu == MenuLeft) ? (width - self.slideOffset ) : ((width - self.slideOffset )* -1 );
298285 [self moveHorizontallyToLocation: rect.origin.x];
299- // self.view.frame = rect;
300286 }
301287 completion: ^(BOOL finished) {
302288 if (completion)
@@ -320,7 +306,6 @@ - (void)closeMenuWithDuration:(float)duration andCompletion:(void (^)())completi
320306 CGRect rect = self.view .frame ;
321307 rect.origin .x = 0 ;
322308 [self moveHorizontallyToLocation: rect.origin.x];
323- // self.view.frame = rect;
324309 }
325310 completion: ^(BOOL finished) {
326311 if (completion)
@@ -371,6 +356,21 @@ - (CGFloat)horizontalLocation
371356 }
372357}
373358
359+ - (CGFloat)horizontalSize
360+ {
361+ CGRect rect = self.view .frame ;
362+ UIInterfaceOrientation orientation = self.interfaceOrientation ;
363+
364+ if (UIInterfaceOrientationIsLandscape (orientation))
365+ {
366+ return rect.size .height ;
367+ }
368+ else
369+ {
370+ return rect.size .width ;
371+ }
372+ }
373+
374374#pragma mark - UINavigationControllerDelegate Methods -
375375
376376- (void )navigationController : (UINavigationController *)navigationController
@@ -419,8 +419,6 @@ - (void)tapDetected:(UITapGestureRecognizer *)tapRecognizer
419419
420420- (void )panDetected : (UIPanGestureRecognizer *)aPanRecognizer
421421{
422- static NSInteger velocityForFollowingDirection = 1000 ;
423-
424422 CGPoint translation = [aPanRecognizer translationInView: aPanRecognizer.view];
425423 CGPoint velocity = [aPanRecognizer velocityInView: aPanRecognizer.view];
426424
@@ -436,7 +434,6 @@ - (void)panDetected:(UIPanGestureRecognizer *)aPanRecognizer
436434
437435 if (newHorizontalLocation >= self.minXForDragging && newHorizontalLocation <= self.maxXForDragging )
438436 [self moveHorizontallyToLocation: newHorizontalLocation];
439- // self.view.frame = rect;
440437
441438 self.draggingPoint = translation;
442439
@@ -458,7 +455,7 @@ - (void)panDetected:(UIPanGestureRecognizer *)aPanRecognizer
458455 NSInteger positiveVelocity = (velocity.x > 0 ) ? velocity.x : velocity.x * -1 ;
459456
460457 // If the speed is high enough follow direction
461- if (positiveVelocity >= velocityForFollowingDirection )
458+ if (positiveVelocity >= MENU_FAST_VELOCITY_FOR_SWIPE_FOLLOW_DIRECTION )
462459 {
463460 // Moving Right
464461 if (velocity.x > 0 )
@@ -502,7 +499,7 @@ - (NSInteger)minXForDragging
502499{
503500 if ([self shouldDisplayMenu: MenuRight forViewController: self .topViewController])
504501 {
505- return (self.view . frame . size . width - self.slideOffset ) * -1 ;
502+ return (self.horizontalSize - self.slideOffset ) * -1 ;
506503 }
507504
508505 return 0 ;
@@ -512,7 +509,7 @@ - (NSInteger)maxXForDragging
512509{
513510 if ([self shouldDisplayMenu: MenuLeft forViewController: self .topViewController])
514511 {
515- return self.view . frame . size . width - self.slideOffset ;
512+ return self.horizontalSize - self.slideOffset ;
516513 }
517514
518515 return 0 ;
0 commit comments