Closing ECSlidingViewController menu
Asked Answered
C

3

7

I'd like to implement my sliding menu in a way that pressing the Menu button will show my menu and pressing Menu again would hide it. But I can't understand how to do it with ECSlidingViewController. Will appreciate any help.

Cheddite answered 27/12, 2013 at 14:4 Comment(0)
A
10

ECSlidingViewController has methods for this: anchorTopViewToRightAnimated:, anchorTopViewToLeftAnimated: and resetTopViewAnimated:.

Example in your top view controller:

[self.slidingViewController anchorTopViewToRightAnimated:YES]

ECSlidingViewController provides a category for UIViewController adding this slidingViewController property.

You may also want to use ECSlidingViewController's currentTopViewPosition to determine if your button should show your menu or hide it in the current context.

Anthem answered 27/12, 2013 at 15:6 Comment(1)
Thanks for pointing out the category I had not seen that and was exactly what I was looking for too.Severini
G
6

I have came up with this question and above answer helps me to resolve it. But I just need to add more detailed answer with code example, so others might get benefit from this if they faced such a problem.

- (IBAction)showSlidingMenu:(id)sender {
   [self.slidingViewController anchorTopViewToRightAnimated:YES];
   if ([self.slidingViewController currentTopViewPosition] == ECSlidingViewControllerTopViewPositionAnchoredRight) {
      [self.slidingViewController resetTopViewAnimated:YES];
   }
}
  • Please note I am animating the top view controller to Right, so I am checking whether top view position is ECSlidingViewControllerTopViewPositionAnchoredRight.
  • Similarly top view position has ECSlidingViewControllerTopViewPositionAnchoredLeft if you are animating to the left.
  • If menu is not showing top view position will get ECSlidingViewControllerTopViewPositionCentered.

+1 for the question and accepted answer

Thanks.

Gomer answered 17/5, 2014 at 5:5 Comment(0)
C
0

According to "ECSlidingViewController sample project" you need to put these 4 lines in ViewWillAppear of FirstTopController(e.g TransitionViewController):

self.slidingViewController.topViewAnchoredGesture = ECSlidingViewControllerAnchoredGestureTapping | ECSlidingViewControllerAnchoredGesturePanning;
self.slidingViewController.customAnchoredGestures = @[];
[self.navigationController.view removeGestureRecognizer:self.dynamicTransitionPanGesture];
[self.navigationController.view addGestureRecognizer:self.slidingViewController.panGesture];

These 4 lines are being used in delegate method of tableview. It might be possible you're not using tableview so these 4 lines are not calling.

Best of Luck..

Cambrian answered 8/7, 2015 at 8:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.