Skip to content

Commit d7ad0e1

Browse files
committed
- Fixed menu rotation issue when app launches in landscape mode
1 parent 17c29fc commit d7ad0e1

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

SlideMenu/Source/SlideNavigationController.m

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ @implementation SlideNavigationController
4545
#define MENU_DEFAULT_SLIDE_OFFSET 60
4646
#define MENU_FAST_VELOCITY_FOR_SWIPE_FOLLOW_DIRECTION 1200
4747
#define MENU_REVEAL_ANIMATION_DEFAULT_SLIDE_MOVEMENT 100
48-
#define MENU_REVEAL_ANIMATION_DEFAULT_FADE_MAXIMUM_ALPHA .7
48+
#define MENU_REVEAL_ANIMATION_DEFAULT_FADE_MAXIMUM_ALPHA .8
4949
#define STATUS_BAR_HEIGHT 20
5050

5151
static SlideNavigationController *singletonInstance;
@@ -111,13 +111,18 @@ - (void)setup
111111
- (void)viewWillLayoutSubviews
112112
{
113113
[super viewWillLayoutSubviews];
114-
114+
115+
// Update shadow size
116+
self.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.bounds].CGPath;
115117
}
116118

117119
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
118120
{
119121
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
120122

123+
// Update rotation animation
124+
[self updateMenuFrameAndTransformAccordingToOrientation];
125+
121126
// Avoid an ugnly shadow in background while rotating
122127
self.view.layer.shadowOpacity = 0;
123128
}
@@ -126,6 +131,14 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO
126131
{
127132
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
128133

134+
self.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.bounds].CGPath;
135+
136+
// we set shadowOpacity to 0 in willRotateToInterfaceOrientation, after the rotation we want to add the shadow back
137+
self.view.layer.shadowOpacity = MENU_SHADOW_OPACITY;
138+
}
139+
140+
- (void)updateMenuFrameAndTransformAccordingToOrientation
141+
{
129142
CGAffineTransform transform = self.view.transform;
130143
self.leftMenu.view.transform = transform;
131144
self.rightMenu.view.transform = transform;
@@ -137,11 +150,6 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO
137150
// Move menus accordingly to avoid a weird animation during opening/closing menu after a rotation
138151
[self updateMenuAnimation:MenuLeft];
139152
[self updateMenuAnimation:MenuRight];
140-
141-
self.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.bounds].CGPath;
142-
143-
// we set shadowOpacity to 0 in willRotateToInterfaceOrientation, after the rotation we want to add the shadow back
144-
self.view.layer.shadowOpacity = MENU_SHADOW_OPACITY;
145153
}
146154

147155
#pragma mark - Public Methods -
@@ -311,7 +319,7 @@ - (void)openMenu:(Menu)menu withDuration:(float)duration andCompletion:(void (^)
311319
{
312320
[self.topViewController.view addGestureRecognizer:self.tapRecognizer];
313321

314-
[self prepareMenuForReveal:menu];
322+
[self prepareMenuForReveal:menu forcePrepare:NO];
315323

316324
[UIView animateWithDuration:duration
317325
delay:0
@@ -427,11 +435,17 @@ - (void)updateMenuAnimation:(Menu)menu
427435
}
428436
}
429437

430-
- (void)prepareMenuForReveal:(Menu)menu
438+
- (void)prepareMenuForReveal:(Menu)menu forcePrepare:(BOOL)forcePrepare
431439
{
440+
// If menu is already open don't prepare, unless forcePrepare is set to true
441+
if ([self isMenuOpen] && !forcePrepare)
442+
return;
443+
432444
UIViewController *menuViewController = (menu == MenuLeft) ? self.leftMenu : self.rightMenu;
433445
UIViewController *removingMenuViewController = (menu == MenuLeft) ? self.rightMenu : self.leftMenu;
434446

447+
[self updateMenuFrameAndTransformAccordingToOrientation];
448+
435449
// If already has been added to the view (has superview) it means it has been initialized so avoid reinitializing
436450
if (menuViewController.view.superview)
437451
return;
@@ -562,15 +576,25 @@ - (void)panDetected:(UIPanGestureRecognizer *)aPanRecognizer
562576
CGPoint velocity = [aPanRecognizer velocityInView:aPanRecognizer.view];
563577
NSInteger movement = translation.x - self.draggingPoint.x;
564578

565-
[self prepareMenuForReveal:(self.horizontalLocation > 0 || (self.horizontalLocation == 0 && translation.x > 0) ) ? MenuLeft : MenuRight];
579+
Menu menu = (self.horizontalLocation > 0 || (self.horizontalLocation == 0 && translation.x > 0) ) ? MenuLeft : MenuRight;
566580

567581
if (aPanRecognizer.state == UIGestureRecognizerStateBegan)
568582
{
583+
[self prepareMenuForReveal:menu forcePrepare:YES];
569584
self.draggingPoint = translation;
570585
}
571586
else if (aPanRecognizer.state == UIGestureRecognizerStateChanged)
572587
{
573-
NSInteger newHorizontalLocation = [self horizontalLocation];
588+
static CGFloat lastHorizontalLocation = 0;
589+
CGFloat newHorizontalLocation = [self horizontalLocation];
590+
591+
// Force prepare menu when slides quickly between left and right menu
592+
if ((lastHorizontalLocation < 0 && newHorizontalLocation > 0) ||
593+
(lastHorizontalLocation > 0 && newHorizontalLocation < 0))
594+
[self prepareMenuForReveal:menu forcePrepare:YES];
595+
596+
lastHorizontalLocation = newHorizontalLocation;
597+
574598
newHorizontalLocation += movement;
575599

576600
if (newHorizontalLocation >= self.minXForDragging && newHorizontalLocation <= self.maxXForDragging)

SlideMenu/en.lproj/MainStoryboard_iPhone.storyboard

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
1515
<subviews>
1616
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="T7T-Ke-Ksy">
17-
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
18-
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
17+
<rect key="frame" x="0.0" y="20" width="320" height="548"/>
18+
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES" heightSizable="YES"/>
1919
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
2020
<prototypes>
2121
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="rightMenuCell" textLabel="69X-Zn-twq" style="IBUITableViewCellStyleDefault" id="Pb7-aS-2IS">
@@ -130,7 +130,7 @@
130130
<navigationItem key="navigationItem" title="No Menu" id="k71-Cl-mOP">
131131
<barButtonItem key="rightBarButtonItem" id="NgO-HE-8LY">
132132
<segmentedControl key="customView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="bar" selectedSegmentIndex="0" id="nE8-Dp-UZR">
133-
<rect key="frame" x="209" y="6" width="95" height="32"/>
133+
<rect key="frame" x="209" y="8" width="95" height="29"/>
134134
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
135135
<segments>
136136
<segment title="Seg 1"/>

0 commit comments

Comments
 (0)