Git Product home page Git Product logo

jvmenupopover's Introduction

JVMenuPopover Version License Platform

This is a simple menu controller where I tried to simulate the native iOS animation of switching between apps. It can be used in many different ways and you can also customize it to use your own animations.

Previews

• Menu with slideInWithBounceAnimation

screenshot-1

• Menu with slideInAnimation

screenshot-1

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Using JVMenuPopover with your own project.

  • Set your RootViewController in the your AppDelegate.m, you could follow my example project and see how I set a background image to the entire app if you are looking to follow the same approach. Also, notice that I am able to set the navigation bar transparent just setting the boolean I have created for it.

    • I use one of my helper functions in the pods to adjust the image to my device width and not show an expanded image.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    self.rootViewController = [[JVMenuRootViewController alloc] init];

    // setting up navigation controller with root controller & transparent nav bar
    self.navigationController = [[JVMenuNavigationController alloc] initWithRootViewController:self.rootViewController];
    self.navigationController.withTransparentNavBar = YES;

    // setting up app window
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window setRootViewController:self.navigationController];
    self.window.backgroundColor = [UIColor colorWithPatternImage:[JVMenuHelper imageWithImage:[UIImage imageNamed:@"app_bg1.jpg"] scaledToWidth:self.window.frame.size.width]];
    self.window.contentMode = UIViewContentModeScaleAspectFit;

    [self.window addSubview:self.navigationController.view];
    [self.window makeKeyAndVisible];

    return YES;
}
  • Here, I set my menu controller with the images I would like to display as icon images, the title for my menu and close menu image. I use a technique known as Lazy Loading which allows me to create my menu at the last minute before adding it to the view.

    • Currently, I am using some regular free images I have added to the same project, but you do this within your root controller and you can load whatever images you want to. Also, the menu will create rows only base on the labels/titles provided and not from how many images you give it to the menu.
- (JVMenuPopoverViewController *)menuController
{
    if(!_menuController)
    {
        _menuController = [[JVMenuPopoverViewController alloc] initWithImages:@[[UIImage imageNamed:@"home-48"],
                                                                                [UIImage imageNamed:@"about-48"],
                                                                                [UIImage imageNamed:@"settings-48"],
                                                                                [UIImage imageNamed:@"business_contact-48"],
                                                                                [UIImage imageNamed:@"ask_question-48"]]
                                                                        titles:@[@"Home",
                                                                                 @"About Us",
                                                                                 @"Our Service",
                                                                                 @"Contact Us",
                                                                                 @"Help?"]
                                                                    closeImage:[UIImage imageNamed:@"cancel_filled-50"]];
        _menuController.delegate = self;
        _menuController.slideInWithBounceAnimation = YES; // choose our animation type
    }

    return _menuController;
}
  • Then, we set our navigation controller, however we wanted it to be displayed.

    • Here, I set the menu image I want to display, the color of the menu button.
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    self.navigationController.delegate = self;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:self.menuImg style:UIBarButtonItemStylePlain target:self action:@selector(showMenu)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
}
  • Finally but not least, I set the showing menu controller from our root controller. Also, we need to implement the close menu button delegate to dismiss the menu and get back to our previous controller. And the setNewViewController delegate which I tell my own navigation controller to handle all the display and animations for presenting new controllers.
// showing menu from our root controller
- (void)showMenu
{
    [self.menuController showMenuFromController:self];
}

// closing menu when close button is pressed
- (void)closeMenu:(JVMenuPopoverViewController *)JVMenuPopoverViewController
{
    [self.navigationController popToViewController:JVMenuPopoverViewController animated:NO];
}

// setting the view controllers to be presented
- (void)setNewViewController:(UINavigationController *)navController fromIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0)
    {
        self.mainController = [[JVMenuRootViewController alloc] init];
        [self.navigationController setViewControllers:@[self.mainController]];
    }
    else if(indexPath.row == 1)
    {
        self.secondController = [[JVMenuSecondController alloc] init];
        [self.navigationController setViewControllers:@[self.secondController]];
    }
}

Requirements

Developed and tested using iOS8+

Installation

JVMenuPopover is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "JVMenuPopover"

Author & Support

Contact me if you find any bugs or potential room for improvements, which I am sure there are. Jorge Valbuena (@JV17), [email protected]. BTW! You are welcome to help in supporting this pod or making improvements to it.

License

JVMenuPopover is available under the MIT license. See the LICENSE file for more info.

jvmenupopover's People

Contributors

jv17 avatar jvdev17 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.