zoukankan      html  css  js  c++  java
  • 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];

  • 相关阅读:
    Hasura GraphQL schema 生成是如何工作的
    一张方便的graphql schema 语言手册
    使用lua graphql 模块让openresty 支持graphql api
    PostgREST docker-compose 试用
    subzero 基于postgrest && openresty && rabbitmq 的快速rest/graphql 开发平台
    使用blessed 开发丰富的cli 应用
    一个方便查看数据库转换rest/graphql api 的开源软件的github 项目
    treeql 基于rest 标准的接口开发协议
    graphql-modules 企业级别的graphql server 工具
    hangfire docker-compose 运行
  • 原文地址:https://www.cnblogs.com/oumygade/p/4280641.html
Copyright © 2011-2022 走看看