30

Possible Duplicate:
What's the best way to develop a sideswipe menu like the one in Facebook's new iOS app?

The facebook iphone app has a new side menu,
screen
(source: tapscape.com)

Does anyone know how i can implement this feature in my iphone application and using objective c?

Community
  • 1
  • 1
Diptesh
  • 383
  • 1
  • 5
  • 14
  • Check [this library](http://www.cocoacontrols.com/platforms/ios/controls/zuuirevealcontroller). Helped me! It is finished library doing that really good! – noctri Jan 01 '12 at 22:13
  • Very simple and easy to use https://github.com/shivamchove/facebook_style_left_menus library – Shivomkara Chaturvedi Jun 18 '13 at 10:25

1 Answers1

49

It's pretty simple really. First, you need to make a view controller that sits under the one that's visible. You can send that view to the back like this:

[self.view sendSubviewToBack:menuViewController.view];

Then, you put a menu button on the left side of your navigation bar, and write a handler kind of like this:

- (void)menuButtonPressed:(id)sender {

    CGRect destination = self.navigationController.view.frame;

    if (destination.origin.x > 0) {
        destination.origin.x = 0;
    } else {
        destination.origin.x += 254.5;
    }

    [UIView animateWithDuration:0.25 animations:^{

        self.navigationController.view.frame = destination;        

    } completion:^(BOOL finished) {

        self.view.userInteractionEnabled = !(destination.origin.x > 0);

    }];
}

That's the general idea. You may have to change the code to reflect your view hierarchy, etc.

greenisus
  • 1,707
  • 14
  • 17
  • 7
    @greenisus I'm confused on how you sent the menu to the back? When I do that it just shows a black side menu. – Bot Jan 19 '12 at 21:20
  • this worked for me, thanks! does anyone know how to handle orientation changes for this side menu? – odaa Mar 08 '12 at 15:03
  • 1
    can i do this for a tab bar view controller . basically planning to hide the tab bar in the bottom – thndrkiss May 22 '12 at 11:52
  • This works when you have 2 UIViewControllers on top of each other and you move the one on top to the side to see the "menu" view under it. I need to have the one on top be a UINavigationController but cannot achieve this. Any help would be appreciated. – C0D3 Oct 10 '12 at 15:30
  • @Bot Were you ever able to get the UIViewController underneath to become visible? – Piotr Tomasik Mar 13 '13 at 23:47
  • How do you add the childViewController's view as a subview? do you set its frame explicitly? – Piotr Tomasik Mar 13 '13 at 23:49
  • @greenisus Whose subview is the childviewcontroller's view and what frame is it given? – Piotr Tomasik Mar 14 '13 at 00:07
  • @Piotr see http://stackoverflow.com/questions/8914070/send-subview-to-back I also have `appointmentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"AppointmentViewController"]; self.navController = [[UINavigationController alloc] initWithRootViewController:appointmentViewController]; self.navController.view.frame = self.contentView.bounds; [self addShadowToMenu]; [self.contentView addSubview:self.navController.view]; self.sideMenu.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];` in my side menu viewDidLoad – Bot Mar 14 '13 at 17:29
  • 1
    I added a button on side view, but when I am trying to click it, it is not responding to associated action :( – Devarshi Jul 28 '13 at 17:54
  • Sorry, I didn't see all these questions until tonight. When I did this, I used UIViewController containment had a UIViewController that had two child UIViewControllers. The button on the "content" view controller would send a message up to the root container view controller and that would handle the animation. – greenisus Jul 29 '13 at 03:35