• iOS 封装Modal动画代码


    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];

  • 相关阅读:
    漫画 | 一台Linux服务器最多能支撑多少个TCP连接(非常重要)
    http请求与http响应
    gin BindJSON
    Joplin开源笔记软件使用入门
    使用pyttsx3实现简单tts服务
    07 | 哨兵机制:主库挂了,如何不间断服务?
    08 | 哨兵集群:哨兵挂了,主从库还能切换吗?
    30 | 如何使用Redis实现分布式锁?
    06 | 数据同步:主从库如何实现数据一致?
    0405 | AOF日志:宕机了,Redis如何避免数据丢失?
  • 原文地址:https://www.cnblogs.com/oumygade/p/4280641.html
Copyright © 2020-2023  润新知