From 7b02207537d35bfa1714bf8beafc921f717d100a Mon Sep 17 00:00:00 2001 From: 单军华 Date: Wed, 11 Jul 2018 10:47:42 +0800 Subject: [PATCH] 首次上传 --- screendisplay/screendisplay/Classes/Helpers/PresentAnimator.m | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 150 insertions(+), 0 deletions(-) diff --git a/screendisplay/screendisplay/Classes/Helpers/PresentAnimator.m b/screendisplay/screendisplay/Classes/Helpers/PresentAnimator.m new file mode 100755 index 0000000..46736e2 --- /dev/null +++ b/screendisplay/screendisplay/Classes/Helpers/PresentAnimator.m @@ -0,0 +1,150 @@ +// +// PresentAnimator.m +// transparentwebview +// +// Created by windshan on 2018/3/14. +// Copyright �� 2018��� prjk. All rights reserved. +// + +#import "PresentAnimator.h" + +void *id_key = &id_key; +@implementation UIViewController (LMJAdd) + +- (void)setId_key:(id)obj { + objc_setAssociatedObject(self, id_key, obj, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + +- (id)id_key +{ + return objc_getAssociatedObject(self, id_key); +} + +@end + +@interface PresentAnimator()<UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning> +{ + BOOL _isPresented; + CGRect _presentViewFrame; + void(^_presentAnimation)(UIView *presentedView, UIView *containerView, void(^completion)(BOOL finished)); + void(^_dismissAnimation)(UIView *dismissView, void(^completion)(BOOL finished)); + CGFloat _animatedDuration; +} + +@end + + +@implementation PresentAnimator + +#pragma mark - UIViewControllerTransitioningDelegate + +- (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source { + // A presentViewController B ������a.presentedViewController������b���b.presentingViewController������a��� + LMJPresentationController *presVc = [[LMJPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting]; + if (!CGRectIsEmpty(_presentViewFrame)) { + presVc.presentViewFrame = _presentViewFrame; + }else { + presVc.presentViewFrame = [UIScreen mainScreen].bounds; + } + + return presVc; +} + +- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source +{ + _isPresented = YES; + return self; +} + +- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed +{ + _isPresented = NO; + return self; +} + + +#pragma mark - UIViewControllerAnimatedTransitioning + +- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext +{ + return _animatedDuration; +} + +- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext +{ + _isPresented ? [self presentAnimateTransition: transitionContext] : [self dismissAnimateTransition: transitionContext]; +} + +- (void)presentAnimateTransition:(id<UIViewControllerContextTransitioning>)transitionContext +{ + // A presentViewController B ������a.presentedViewController������b���b.presentingViewController������a��� + UIView *containerView = transitionContext.containerView; + UIView *presentedView = [transitionContext viewForKey:UITransitionContextToViewKey]; + [containerView addSubview:presentedView]; + + if (_presentAnimation) { + TWWeak(presentedView); + TWWeak(transitionContext); + TWWeak(containerView); + _presentAnimation(weakpresentedView, weakcontainerView, ^void(BOOL isFinished){ + ///���view������������������������������, ������������������������������ + [weaktransitionContext completeTransition:isFinished]; + }); + }else { + ///���view������������������������������, ������������������������������ + [transitionContext completeTransition:YES]; + } +} + +- (void)dismissAnimateTransition:(id<UIViewControllerContextTransitioning>)transitionContext +{ + // A presentViewController B ������a.presentedViewController������b���b.presentingViewController������a��� + UIView *dismissView = [transitionContext viewForKey:UITransitionContextFromViewKey]; + + if (_dismissAnimation) { + TWWeak(dismissView); + TWWeak(transitionContext); + _dismissAnimation(weakdismissView, ^void(BOOL isFinished){ + [weakdismissView removeFromSuperview]; + ///���view������������������������������, ������������������������������ + [weaktransitionContext completeTransition:isFinished]; + }); + }else { + [dismissView removeFromSuperview]; + ///���view������������������������������, ������������������������������ + [transitionContext completeTransition:YES]; + } +} + + ++ (void)viewController:(UIViewController *)viewController presentViewController:(UIViewController *)presentViewController presentViewFrame:(CGRect)presentViewFrame animated:(BOOL)animated completion:(void (^)(void))completion animatedDuration:(NSTimeInterval)duration presentAnimation:(void(^)(UIView *presentedView, UIView *containerView, void(^completionHandler)(BOOL finished)))presentAnimation dismissAnimation:(void(^)(UIView *dismissView, void(^completionHandler)(BOOL finished)))dismissAnimation +{ + PresentAnimator *animator = [[PresentAnimator alloc] init]; + animator->_presentViewFrame = presentViewFrame; + animator->_animatedDuration = duration; + animator->_presentAnimation = [presentAnimation copy]; + animator->_dismissAnimation = [dismissAnimation copy]; + [presentViewController setId_key:animator]; + presentViewController.modalPresentationStyle = UIModalPresentationCustom; + presentViewController.transitioningDelegate = animator; + [viewController presentViewController:presentViewController animated:animated completion:completion]; +} + +@end + + +@implementation LMJPresentationController + +- (void)containerViewWillLayoutSubviews { + [super containerViewWillLayoutSubviews]; + self.presentedView.frame = self.presentViewFrame; +} + +@end + + + + + + + -- Gitblit v1.8.0