如何将自定义的present和dismiss动画改写为具有长尾词的?
- 内容介绍
- 文章标签
- 相关推荐
本文共计645个文字,预计阅读时间需要3分钟。
为了更好地管理项目进度,我将重新编写关于present和push的定制动画。之前因时间紧迫未能整理解释,导致部分内容混乱,以下为改进后的内容:
在项目管理中,我们经常使用present和push这两个动作。下面,我将自定义这两个动作的动画效果:
1. present 动画: - 动画效果:淡入显示,配合文字滚动效果。 - 应用场景:用于展示项目关键信息或里程碑。
2. push 动画: - 动画效果:从右向左滑动,逐渐显示内容。 - 应用场景:用于更新项目进度或添加新任务。
通过上述动画,我们可以使项目展示更加生动、直观。
趁周末闲暇之余重新写一下present和push的自定义动画。 本来之前有写过一个因为没有及时整理到导致一时凌乱找不到具体在哪了提醒各位平时要注意代码的整理和归档不然到时候重复的代码写了又写那就得不偿失了。废话不过说先看下下面的效果
原生的present是从底部向上弹出相应的视图控制器而push动画则是将视图从右边推出来进行展示为了视图展示的统一性需要自定义转场动画将present改成从右往左推出来展示在dismiss的VC中需要增加一个左边的手势以满足侧滑返回的效果。
首先需要主页VC实现UIViewControllerTransitioningDelegate这个代理中的2个方法
#pragma mark - UIViewControllerTransitioningDelegate- (id)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source{return [[YQPresentTransitionAnimated alloc] init];}- (id )animationControllerForDismissedController:(UIViewController *)dismissed {return [[YQDismissTransitionAnimated alloc] init];}
将它的present动画和dismiss动画交给我们自定义的动画来管理。
####present动画的自定义#### 1.创建一个类继承至NSObject,并实现UIViewControllerAnimatedTransitioning的代理;
#import #import interface YQPresentTransitionAnimated : NSObjectend
2.实现代理的2个方法
//1.定义转场动画的时间- (NSTimeInterval)transitionDuration:(id)transitionContext {return 0.4;}//2.实现转场动画的动画效果- (void)animateTransition:(id)transitionContext {UIViewController *fromViewController [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; //主页VCUIViewController *toViewController [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; //present的VCUIView *containerView transitionContext.containerView; //转场的容器视图动画完成后会消失UIView *fromView;UIView *toView;if ([transitionContext respondsToSelector:selector(viewForKey:)]) {fromView [transitionContext viewForKey:UITransitionContextFromViewKey];toView [transitionContext viewForKey:UITransitionContextToViewKey];} else {fromView fromViewController.view;toView toViewController.view;}//注意这个对应关系BOOL isPresenting (toViewController.presentingViewController fromViewController);CGRect fromFrame [transitionContext initialFrameForViewController:fromViewController];CGRect toFrame [transitionContext finalFrameForViewController:toViewController];if (isPresenting) {fromView.frame fromFrame;toView.frame CGRectOffset(toFrame, toFrame.size.width, 0);}if (isPresenting)[containerView addSubview:toView];NSTimeInterval transitionDuration [self transitionDuration:transitionContext];[UIView animateWithDuration:transitionDuration animations:^{if (isPresenting) {toView.frame toFrame;fromView.frame CGRectOffset(fromFrame, fromFrame.size.width * 0.3 * -1, 0);}} completion:^(BOOL finished) {//固定写法BOOL wasCancelled [transitionContext transitionWasCancelled];if (wasCancelled)[toView removeFromSuperview];[transitionContext completeTransition:!wasCancelled];}];}
3.将主页VC的transitioningDelegate设为自己****还需要将present的页面的transitioningDelegate设为自己主页VC
####dismiss动画的自定义#### 跟上面的present步骤一样只需将动画效果换成相反的即可。
附上源码 github.com/GitterYang/…
转载于:juejin.im/post/5a3c80d3f265da43176a53a2
本文共计645个文字,预计阅读时间需要3分钟。
为了更好地管理项目进度,我将重新编写关于present和push的定制动画。之前因时间紧迫未能整理解释,导致部分内容混乱,以下为改进后的内容:
在项目管理中,我们经常使用present和push这两个动作。下面,我将自定义这两个动作的动画效果:
1. present 动画: - 动画效果:淡入显示,配合文字滚动效果。 - 应用场景:用于展示项目关键信息或里程碑。
2. push 动画: - 动画效果:从右向左滑动,逐渐显示内容。 - 应用场景:用于更新项目进度或添加新任务。
通过上述动画,我们可以使项目展示更加生动、直观。
趁周末闲暇之余重新写一下present和push的自定义动画。 本来之前有写过一个因为没有及时整理到导致一时凌乱找不到具体在哪了提醒各位平时要注意代码的整理和归档不然到时候重复的代码写了又写那就得不偿失了。废话不过说先看下下面的效果
原生的present是从底部向上弹出相应的视图控制器而push动画则是将视图从右边推出来进行展示为了视图展示的统一性需要自定义转场动画将present改成从右往左推出来展示在dismiss的VC中需要增加一个左边的手势以满足侧滑返回的效果。
首先需要主页VC实现UIViewControllerTransitioningDelegate这个代理中的2个方法
#pragma mark - UIViewControllerTransitioningDelegate- (id)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source{return [[YQPresentTransitionAnimated alloc] init];}- (id )animationControllerForDismissedController:(UIViewController *)dismissed {return [[YQDismissTransitionAnimated alloc] init];}
将它的present动画和dismiss动画交给我们自定义的动画来管理。
####present动画的自定义#### 1.创建一个类继承至NSObject,并实现UIViewControllerAnimatedTransitioning的代理;
#import #import interface YQPresentTransitionAnimated : NSObjectend
2.实现代理的2个方法
//1.定义转场动画的时间- (NSTimeInterval)transitionDuration:(id)transitionContext {return 0.4;}//2.实现转场动画的动画效果- (void)animateTransition:(id)transitionContext {UIViewController *fromViewController [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; //主页VCUIViewController *toViewController [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; //present的VCUIView *containerView transitionContext.containerView; //转场的容器视图动画完成后会消失UIView *fromView;UIView *toView;if ([transitionContext respondsToSelector:selector(viewForKey:)]) {fromView [transitionContext viewForKey:UITransitionContextFromViewKey];toView [transitionContext viewForKey:UITransitionContextToViewKey];} else {fromView fromViewController.view;toView toViewController.view;}//注意这个对应关系BOOL isPresenting (toViewController.presentingViewController fromViewController);CGRect fromFrame [transitionContext initialFrameForViewController:fromViewController];CGRect toFrame [transitionContext finalFrameForViewController:toViewController];if (isPresenting) {fromView.frame fromFrame;toView.frame CGRectOffset(toFrame, toFrame.size.width, 0);}if (isPresenting)[containerView addSubview:toView];NSTimeInterval transitionDuration [self transitionDuration:transitionContext];[UIView animateWithDuration:transitionDuration animations:^{if (isPresenting) {toView.frame toFrame;fromView.frame CGRectOffset(fromFrame, fromFrame.size.width * 0.3 * -1, 0);}} completion:^(BOOL finished) {//固定写法BOOL wasCancelled [transitionContext transitionWasCancelled];if (wasCancelled)[toView removeFromSuperview];[transitionContext completeTransition:!wasCancelled];}];}
3.将主页VC的transitioningDelegate设为自己****还需要将present的页面的transitioningDelegate设为自己主页VC
####dismiss动画的自定义#### 跟上面的present步骤一样只需将动画效果换成相反的即可。
附上源码 github.com/GitterYang/…
转载于:juejin.im/post/5a3c80d3f265da43176a53a2

