secondVC *second = [[secondVC alloc] init];
second.modalPresentationStyle = UIModalPresentationCustom;
second.transitioningDelegate = 自定义一个代理;
[self presentViewController:second animated:YES completion:nil];
// MYTransition.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "Singleton.h"
@interface MYTransition : NSObject<UIViewControllerTransitioningDelegate>
SingletonH(MYTransition)
@end
// MYTransition.m
#import "MYTransition.h"
#import "MYPresentationController.h"
#import "MYAnimatedTransition.h"
#import "UIView+MJ.h"
@implementation MYTransition
SingletonM(MYTransition)
#pragma mark - UIViewControllerTransitioningDelegate
- (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source
{
return [[MYPresentationController alloc]initWithPresentedViewController:presented presentingViewController:presenting];
}
- (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source
{
MYAnimatedTransition *anima = [[MYAnimatedTransition alloc]init];
anima.show = YES;
return anima;
}
- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed
{
MYAnimatedTransition *anima = [[MYAnimatedTransition alloc]init];
anima.show = NO;
return anima;
}
@end
secondVC *second = [[secondVC alloc] init];
second.modalPresentationStyle = UIModalPresentationCustom;
second.transitioningDelegate = [MYTransition sharedMYTransition];
[self presentViewController:second animated:YES completion:nil];
原文:http://www.cnblogs.com/oumygade/p/4280641.html