Skip to content

Commit 439a6d7

Browse files
committed
- Added bounce functionality (Let's say the right menu is for notifications, when you receive notification you bounce the right menu to let the user know that they should open the right menu to view the notification)
1 parent 220512c commit 439a6d7

File tree

5 files changed

+70
-13
lines changed

5 files changed

+70
-13
lines changed

SlideMenu/Helper Classes/HomeViewController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@
1111

1212
@interface HomeViewController : UIViewController <SlideNavigationControllerDelegate>
1313

14+
- (IBAction)bounceMenu:(id)sender;
15+
1416
@end

SlideMenu/Helper Classes/HomeViewController.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,15 @@ - (BOOL)slideNavigationControllerShouldDisplayRightMenu
2727
return YES;
2828
}
2929

30+
#pragma mark - IBActions -
31+
32+
- (IBAction)bounceMenu:(id)sender
33+
{
34+
static Menu menu = MenuLeft;
35+
36+
[[SlideNavigationController sharedInstance] bounceMenu:menu withCompletion:nil];
37+
38+
menu = (menu == MenuLeft) ? MenuRight : MenuLeft;
39+
}
40+
3041
@end

SlideMenu/Source/SlideNavigationController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ typedef enum{
5454

5555
+ (SlideNavigationController *)sharedInstance;
5656
- (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion;
57+
- (void)bounceMenu:(Menu)menu withCompletion:(void (^)())completion;
5758
- (void)openMenu:(Menu)menu withCompletion:(void (^)())completion;
5859
- (void)closeMenuWithCompletion:(void (^)())completion;
5960
- (void)toggleLeftMenu;

SlideMenu/Source/SlideNavigationController.m

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,41 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO
136136
self.view.layer.shadowOpacity = MENU_SHADOW_OPACITY;
137137
}
138138

139-
- (void)updateMenuFrameAndTransformAccordingToOrientation
140-
{
141-
// Animate rotatation when menu is open and device rotates
142-
CGAffineTransform transform = self.view.transform;
143-
self.leftMenu.view.transform = transform;
144-
self.rightMenu.view.transform = transform;
145-
146-
self.leftMenu.view.frame = [self initialRectForMenu];
147-
self.rightMenu.view.frame = [self initialRectForMenu];
148-
}
149-
150139
#pragma mark - Public Methods -
151140

141+
- (void)bounceMenu:(Menu)menu withCompletion:(void (^)())completion
142+
{
143+
[self prepareMenuForReveal:menu forcePrepare:YES];
144+
NSInteger movementDirection = (menu == MenuLeft) ? 1 : -1;
145+
146+
[UIView animateWithDuration:.16 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
147+
[self moveHorizontallyToLocation:30*movementDirection];
148+
} completion:^(BOOL finished){
149+
[UIView animateWithDuration:.1 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
150+
[self moveHorizontallyToLocation:0];
151+
} completion:^(BOOL finished){
152+
[UIView animateWithDuration:.12 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
153+
[self moveHorizontallyToLocation:16*movementDirection];
154+
} completion:^(BOOL finished){
155+
[UIView animateWithDuration:.08 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
156+
[self moveHorizontallyToLocation:0];
157+
} completion:^(BOOL finished){
158+
[UIView animateWithDuration:.08 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
159+
[self moveHorizontallyToLocation:6*movementDirection];
160+
} completion:^(BOOL finished){
161+
[UIView animateWithDuration:.06 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
162+
[self moveHorizontallyToLocation:0];
163+
} completion:^(BOOL finished){
164+
if (completion)
165+
completion();
166+
}];
167+
}];
168+
}];
169+
}];
170+
}];
171+
}];
172+
}
173+
152174
- (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion
153175
{
154176
if (self.avoidSwitchingToSameClassViewController && [self.topViewController isKindOfClass:viewController.class])
@@ -262,6 +284,17 @@ - (NSArray *)popToViewController:(UIViewController *)viewController animated:(BO
262284

263285
#pragma mark - Private Methods -
264286

287+
- (void)updateMenuFrameAndTransformAccordingToOrientation
288+
{
289+
// Animate rotatation when menu is open and device rotates
290+
CGAffineTransform transform = self.view.transform;
291+
self.leftMenu.view.transform = transform;
292+
self.rightMenu.view.transform = transform;
293+
294+
self.leftMenu.view.frame = [self initialRectForMenu];
295+
self.rightMenu.view.frame = [self initialRectForMenu];
296+
}
297+
265298
- (void)enableTapGestureToCloseMenu:(BOOL)enable
266299
{
267300
if (enable)

SlideMenu/en.lproj/MainStoryboard_iPhone.storyboard

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@
9494
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
9595
<subviews>
9696
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="0tp-7h-5YK">
97-
<rect key="frame" x="75" y="150" width="133" height="30"/>
97+
<rect key="frame" x="54" y="150" width="212" height="30"/>
9898
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
99-
<state key="normal" title="Push Another Page">
99+
<state key="normal" title="Push me somewhere else">
100100
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
101101
</state>
102102
<connections>
@@ -110,6 +110,16 @@
110110
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
111111
<nil key="highlightedColor"/>
112112
</label>
113+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="Pmu-aT-jf0">
114+
<rect key="frame" x="75" y="206" width="79" height="30"/>
115+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
116+
<state key="normal" title="Bounce Me">
117+
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
118+
</state>
119+
<connections>
120+
<action selector="bounceMenu:" destination="mAB-md-uek" eventType="touchUpInside" id="ypv-y6-6jh"/>
121+
</connections>
122+
</button>
113123
</subviews>
114124
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
115125
</view>

0 commit comments

Comments
 (0)