Skip to content

iOS 7 style custom transition classes for presenting rotation-friendly modal view controllers

License

Notifications You must be signed in to change notification settings

edison9888/MVModalTransitions

Repository files navigation

MVModalTransitions

This is a light-weight library to present custom view controllers on iPad and iPhone without recurring to the UIModalPresentationFormSheet and UIModalPresentationPageSheet presentation styles (which are only available on iPad).

With iOS 7, Apple introduced the new View Controller Transitioning APIs. These are used by the MVModalTransition and MVPopupTransition classes to present non-fullscreen interface-rotation friendly modal view controllers. The MVModalTransition class can be used as a base class to implement custom transitions and provides support for adding a semi-transparent full-screen background view.

This sample project comes with a custom modal picker view that illustrates how to use this.

Usage

/* -- Presented view controller code -- */
@interface MVCustomAlertView ()
@property(strong, nonatomic) MVPopupTransition *animator;
@end

@implementation MVCustomAlertView

- (id)init {

    if ((self = [super init])) {
        self.modalPresentationStyle = UIModalPresentationCustom;
        self.transitioningDelegate = self;
        self.animator = [MVPopupTransition createWithSize:CGSizeMake(300, 300) dimBackground:YES shouldDismissOnBackgroundViewTap:NO delegate:nil];
    }
    return self;
}

#pragma mark - UIViewControllerTransitioningDelegate

- (id )animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source
{
    return self.animator;
}

- (id )animationControllerForDismissedController:(UIViewController *)dismissed
{
    return self.animator;
}
@end


/* -- Presenting view controller code -- */
@implementation PresentingViewController

// Handler
- (void)buttonPressed {

  MVCustomAlertView *vc = [MyViewController new];
  [self presentViewController:vc animated:YES completion:nil];  
}

Installation

This example uses Masonry on top of Auto-Layout. The corresponding pod needs to be installed before the project can be built.

pod install

Scope

The custom popup transition can be used to present modal view controllers as long as:

  • their size doesn't change with interface rotation
  • their width and height do not exceed the smallest of the screen dimensions

License

License information can be found in the LICENSE.md file.

Preview

Modal View Controllers Preview

Contact

Andrea Bizzotto - [email protected]

About

iOS 7 style custom transition classes for presenting rotation-friendly modal view controllers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published