码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 封装Modal动画代码

时间:2015-02-09 00:36:27      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

1.自定义转场动画要写的代码很多,如果整个项目的转场动画都必须一致,则必须考虑把modal代码封装起来

    secondVC *second = [[secondVC alloc] init];

    second.modalPresentationStyle = UIModalPresentationCustom;

    second.transitioningDelegate = 自定义一个代理;

    [self presentViewController:second animated:YES completion:nil];

 

2. 自定义代理对象

// 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

 

3. 使用封装好的Modal动画,就非常简单了

    secondVC *second = [[secondVC alloc] init];

    second.modalPresentationStyle = UIModalPresentationCustom;

    second.transitioningDelegate = [MYTransition sharedMYTransition];    

    [self presentViewController:second animated:YES completion:nil];

 

iOS 封装Modal动画代码

标签:

原文地址:http://www.cnblogs.com/oumygade/p/4280641.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!