MaryPopin

Category to display modal-like view controllers with more options


Project maintained by Backelite Hosted on GitHub Pages — Theme by mattgraham
Backelite is hiring (french)

MaryPopin

MaryPopin is a category on UIViewController to present modal like controller with more flexibility.

- Wait, what? There are tons of similar projects on the web to do that!

Well, your are right, but here are some strengths of this project :

Yes, you can say it, it is Supercalifragilisticexpialidocious!

- Okay. But why MaryPopin? Popin, popup, modal may look similar, but in reality, there are some slight differences. Here, the controller view is presented inside its parent controller that is why we name it a popin controller. And as it is implemented as a category, it is as nice and magic as the famous nanny.

MaryPopin demo

Changes

v 1.0

Getting started

The Pod way

Just add the following line in your podfile

pod 'MaryPopin'

The old school way

Drag and drop the category files in your project and you are done.

Using MaryPopin

Basic usage

First, import UIViewController+MaryPopin.h header.

In your current view controller, you can create a view controller and present it as a popin.

    //Create the popin view controller
    UIViewController *popin = [[UIViewController alloc] initWithNibName:@"NibName" bundle:@"Bundle"];
    //Customize transition if needed
        [popin setPopinTransitionStyle:BKTPopinTransitionStyleSlide];

        //Add options
        [popin setPopinOptions:BKTPopinDisableAutoDismiss];

        //Customize transition direction if needed
        [popin setPopinTransitionDirection:BKTPopinTransitionDirectionTop];

        //Present popin on the desired controller
        //Note that if you are using a UINavigationController, the navigation bar will be active if you present
        // the popin on the visible controller instead of presenting it on the navigation controller
        [self presentPopinController:popin animated:YES completion:^{
            NSLog(@"Popin presented !");
        }];

Respectively, to dismiss the popin from your current view controller

    [self dismissCurrentPopinControllerAnimated:YES completion:^{
        NSLog(@"Popin dismissed !");
    }];

Advanced usage

By default, popin is centered in the parent controller view. But you can provide a CGRect in which the popin should be centered. Note that the CGRect must be included in the parent controller view bounds, otherwise it may lead to unexpected behaviors.

    BKTPopinControllerViewController *popin = [[BKTPopinControllerViewController alloc] init];
    [popin setPopinTransitionStyle:BKTPopinTransitionStyleCrossDissolve];
    [popin setPopinTransitionDirection:BKTPopinTransitionDirectionTop];

    CGRect presentationRect = CGRectOffset(CGRectInset(self.view.bounds, 0.0, 100.0), 0.0, 200.0);
    [self.navigationController presentPopinController:popin fromRect:presentationRect animated:YES completion:^{
        NSLog(@"Popin presented !");
    }];

Sample project

The sample project show how to present and dismiss a popin with different transition styles.

Requirements

MaryPopin requires iOS 7.0 and Xcode 5 as it uses UIKit Dynamics and motion effects.

ARC

MaryPopin uses ARC.
If you are using MaryPopin in a non-arc project, you will need to set a -fobjc-arc compiler flag on every MaryPopin source files.
To set a compiler flag in Xcode, go to your active target and select the "Build Phases" tab. Then select MaryPopin source files, press Enter, insert -fobjc-arc and then "Done" to enable ARC for MaryPopin.

Contributing

Contributions for bug fixing or improvements are welcomed. Feel free to submit a pull request.

Licence

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