• iOS 自定义viewController 切换 (modal)


    自己写的一个modal 显示 ,为了解决 modal显示不能全屏的问题 代码如下:

    类 实现动画协议

    #import <Foundation/Foundation.h>

    @interface TransitionDelegate : NSObject

    @property (nonatomic, weak) UIViewController *delegate;

    • (id)initWithDelegate:(UIViewController *)delegate;
    • (void)presentViewController:(UIViewController *)modalViewController;
      @end

    #import "TransitionDelegate.h"
    #import "AnimatedTransitioning.h"
    #import "AnimatedTransitioningDismiss.h"

    @implementation TransitionDelegate
    //===================================================================
    // - UIViewControllerTransitioningDelegate
    //===================================================================

    • (id)initWithDelegate:(UIViewController *)delegate
      {
      self = [super init];
      if (self) {
      self.delegate = delegate;
      }
      return self;
      }

    • (void)presentViewController:(UIViewController *)modalViewController
      {
      modalViewController.modalPresentationStyle = UIModalPresentationCustom;
      modalViewController.transitioningDelegate = self;
      [self.delegate presentViewController:modalViewController animated:YES completion:^{
      }];
      }

    • (id )animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
      id animator;
      animator = [[AnimatedTransitioning alloc] init];
      return animator;
      }

    • (id )animationControllerForDismissedController:(UIViewController *)dismissed {

      id animator;
      animator = [[AnimatedTransitioningDismiss alloc] init];
      return animator;
      }

    @end

    类 实现显示动画

    #import <Foundation/Foundation.h>

    @interface AnimatedTransitioning : NSObject

    @end

    #import "AnimatedTransitioning.h"

    @implementation AnimatedTransitioning

    //===================================================================
    // - UIViewControllerAnimatedTransitioning
    //===================================================================

    • (NSTimeInterval)transitionDuration:(id )transitionContext {
      return 0.25f;
      }

    • (void)animateTransition:(id )transitionContext {

      UIView *inView = [transitionContext containerView];
      UIViewController *toVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
      UIViewController *fromVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];

      [inView addSubview:toVC.view];

      CGRect screenRect = [[UIScreen mainScreen] bounds];
      [toVC.view setFrame:CGRectMake(0, screenRect.size.height, fromVC.view.frame.size.width, fromVC.view.frame.size.height)];

      [UIView animateWithDuration:0.25f
      animations:^{

                         [toVC.view setFrame:CGRectMake(0, 0, fromVC.view.frame.size.width, fromVC.view.frame.size.height)];
                     }
                     completion:^(BOOL finished) {
                         [transitionContext completeTransition:YES];
                     }];
      

    }

    @end

    类 实现dismiss动画

    import <Foundation/Foundation.h>

    @interface AnimatedTransitioningDismiss : NSObject

    @end

    #import "AnimatedTransitioningDismiss.h"

    @implementation AnimatedTransitioningDismiss

    • (NSTimeInterval)transitionDuration:(id)transitionContext
      {
      return 0.25f;
      }

    • (void)animateTransition:(id)transitionContext
      {
      UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];

      CGRect initialFrame = [transitionContext initialFrameForViewController:fromVC];

      CGRect finalFrame = CGRectOffset(initialFrame, 0, CGRectGetHeight(transitionContext.containerView.frame));

      UIViewAnimationOptions opts = UIViewAnimationOptionCurveLinear;

      [UIView animateWithDuration:[self transitionDuration:transitionContext] delay:0 options:opts animations:^{
      fromVC.view.frame = finalFrame;
      } completion:^(BOOL finished) {
      [transitionContext completeTransition:![transitionContext transitionWasCancelled]];
      }];
      }

    @end

    调用方式 [self.transitioningDelegate presentViewController:sns];

  • 相关阅读:
    tcp/udp高并发和高吐吞性能测试工具
    beetle.express针对websocket的高性能处理
    深度神经网络(DNN)反向传播算法(BP)
    深度神经网络(DNN)模型与前向传播算法
    分解机(Factorization Machines)推荐算法原理
    用Spark学习矩阵分解推荐算法
    SimRank协同过滤推荐算法
    矩阵分解在协同过滤推荐算法中的应用
    协同过滤推荐算法总结
    用Spark学习FP Tree算法和PrefixSpan算法
  • 原文地址:https://www.cnblogs.com/xlliang/p/4186630.html
Copyright © 2020-2023  润新知