区块链技术博客
www.b2bchain.cn

iOS 自定义转场求职学习资料

本文介绍了iOS 自定义转场求职学习资料,有助于帮助完成毕业设计以及求职,是一篇很好的资料。

对技术面试,学习经验等有一些体会,在此分享。

前言

转场简单来说就是从一个VC转到另一个VC,系统提供了两大类转场方式:
1. NavigationControllerpush/pop
2. ViewControllerpresent(以前称为modal模态转场,老接口modalPresent被废弃了)

present系统模态转场

在讲解自定义转场前,先把系统封装好的模态转场弄懂

[presentingVC presentViewController: presentedVC animatd: YES completion: NULL]

很简单,presentingVC上弹出了presentedVC,但默认情况下(iPhone11+14)是这样的:

iOS 自定义转场

但实际上可以自己控制模态弹起的样式,UIViewController有两个属性可以选择不同样式:
1. modalPresentationStyle : 转场完成时的presentedVC的展示状态
2. modalTransitionStyle : 转场动画样式

要注意的是,这两个属性更改都要在presentedVC上才能生效

typedef NS_ENUM(NSInteger, UIModalTransitionStyle) {     UIModalTransitionStyleCoverVertical = 0, // 从屏幕下方弹出,默认且常用     UIModalTransitionStyleFlipHorizontal API_UNAVAILABLE(tvos), // 旋转门效果,比较丑     UIModalTransitionStyleCrossDissolve, // 应该是控制alpha变化,也比较常用     UIModalTransitionStylePartialCurl API_AVAILABLE(ios(3.2)) API_UNAVAILABLE(tvos), // 翻书样式,很丑 };
typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {     UIModalPresentationFullScreen = 0,     UIModalPresentationPageSheet ,     UIModalPresentationFormSheet ,     UIModalPresentationCurrentContext ,     UIModalPresentationCustom ,     UIModalPresentationOverFullScreen ,     UIModalPresentationOverCurrentContext ,     UIModalPresentationPopover ,     UIModalPresentationBlurOverFullScreen ,     UIModalPresentationNone API_AVAILABLE(ios(7.0)) = -1,     UIModalPresentationAutomatic API_AVAILABLE(ios(13.0)) = -2, };

presentStyle建议参考这篇博客

需要注意的是,虽然FullScreen是默认值,但在实际测试时(iphone 8/XR + 14)发现,在初始化ViewController后默认值是PageSheet,所以建议在present前显式的确定PresentationStyle


Present自定义转场

自定义转场主要参考了这一篇文章

最简单的自定义Present转场的实现我将其分为三部分实现:

1 设置presentedVC的transitioningDelegate

self.ctd = [ConfirmTransitionDelegate new]; PresentedViewController *pvc = [PresentedViewController new]; pvc.transitioningDelegate = self.ctd; [self presentViewController:pvc animated:YES completion:nil];

而ConfirmTransitionDelegate自然要遵循相应的协议UIViewControllerTransitioningDelegate:

UIViewControllerTransitioningDelegate里都是Optional,最简单的是实现以下两个代理方法:

- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {     return [CrossDissolveAnimator new]; }  - (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {     return [CrossDissolveAnimator new]; }

分别返回跳转和消失的AnimatorController(当然也可以返回不一样的Animator),下面实现CrossDissolveAnimator:

不过通常上presentedVC的transitioningDelegate都是presentingVC

 - (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {     return 0.25; }  - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {      UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];     UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];      UIView *fromView = nil;     UIView *toView = nil;     if ([transitionContext respondsToSelector:@selector(viewForKey:)]) {         fromView = [transitionContext viewForKey:UITransitionContextFromViewKey];         toView = [transitionContext viewForKey:UITransitionContextToViewKey];     } else {         fromView = fromVC.view;         toView = toVC.view;     }      UIView *containerView = transitionContext.containerView;      fromView.frame = [transitionContext initialFrameForViewController:fromVC];     toView.frame = [transitionContext finalFrameForViewController:toVC];      fromView.alpha = 1.0;     toView.alpha = 0;      [containerView addSubview:toView];      [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{         fromView.alpha = 0;         toView.alpha = 1.0;     } completion:^(BOOL finished) {         [transitionContext completeTransition:![transitionContext transitionWasCancelled]];     }]; }

上面的代码就大致手动实现了UIModalTransitionStyleCrossDissolve的这个效果

前言

转场简单来说就是从一个VC转到另一个VC,系统提供了两大类转场方式:
1. NavigationControllerpush/pop
2. ViewControllerpresent(以前称为modal模态转场,老接口modalPresent被废弃了)

present系统模态转场

在讲解自定义转场前,先把系统封装好的模态转场弄懂

[presentingVC presentViewController: presentedVC animatd: YES completion: NULL]

很简单,presentingVC上弹出了presentedVC,但默认情况下(iPhone11+14)是这样的:

iOS 自定义转场

但实际上可以自己控制模态弹起的样式,UIViewController有两个属性可以选择不同样式:
1. modalPresentationStyle : 转场完成时的presentedVC的展示状态
2. modalTransitionStyle : 转场动画样式

要注意的是,这两个属性更改都要在presentedVC上才能生效

typedef NS_ENUM(NSInteger, UIModalTransitionStyle) {     UIModalTransitionStyleCoverVertical = 0, // 从屏幕下方弹出,默认且常用     UIModalTransitionStyleFlipHorizontal API_UNAVAILABLE(tvos), // 旋转门效果,比较丑     UIModalTransitionStyleCrossDissolve, // 应该是控制alpha变化,也比较常用     UIModalTransitionStylePartialCurl API_AVAILABLE(ios(3.2)) API_UNAVAILABLE(tvos), // 翻书样式,很丑 };
typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {     UIModalPresentationFullScreen = 0,     UIModalPresentationPageSheet ,     UIModalPresentationFormSheet ,     UIModalPresentationCurrentContext ,     UIModalPresentationCustom ,     UIModalPresentationOverFullScreen ,     UIModalPresentationOverCurrentContext ,     UIModalPresentationPopover ,     UIModalPresentationBlurOverFullScreen ,     UIModalPresentationNone API_AVAILABLE(ios(7.0)) = -1,     UIModalPresentationAutomatic API_AVAILABLE(ios(13.0)) = -2, };

presentStyle建议参考这篇博客

需要注意的是,虽然FullScreen是默认值,但在实际测试时(iphone 8/XR + 14)发现,在初始化ViewController后默认值是PageSheet,所以建议在present前显式的确定PresentationStyle


Present自定义转场

自定义转场主要参考了这一篇文章

最简单的自定义Present转场的实现我将其分为三部分实现:

1 设置presentedVC的transitioningDelegate

self.ctd = [ConfirmTransitionDelegate new]; PresentedViewController *pvc = [PresentedViewController new]; pvc.transitioningDelegate = self.ctd; [self presentViewController:pvc animated:YES completion:nil];

而ConfirmTransitionDelegate自然要遵循相应的协议UIViewControllerTransitioningDelegate:

UIViewControllerTransitioningDelegate里都是Optional,最简单的是实现以下两个代理方法:

- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {     return [CrossDissolveAnimator new]; }  - (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {     return [CrossDissolveAnimator new]; }

分别返回跳转和消失的AnimatorController(当然也可以返回不一样的Animator),下面实现CrossDissolveAnimator:

不过通常上presentedVC的transitioningDelegate都是presentingVC

 - (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {     return 0.25; }  - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {      UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];     UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];      UIView *fromView = nil;     UIView *toView = nil;     if ([transitionContext respondsToSelector:@selector(viewForKey:)]) {         fromView = [transitionContext viewForKey:UITransitionContextFromViewKey];         toView = [transitionContext viewForKey:UITransitionContextToViewKey];     } else {         fromView = fromVC.view;         toView = toVC.view;     }      UIView *containerView = transitionContext.containerView;      fromView.frame = [transitionContext initialFrameForViewController:fromVC];     toView.frame = [transitionContext finalFrameForViewController:toVC];      fromView.alpha = 1.0;     toView.alpha = 0;      [containerView addSubview:toView];      [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{         fromView.alpha = 0;         toView.alpha = 1.0;     } completion:^(BOOL finished) {         [transitionContext completeTransition:![transitionContext transitionWasCancelled]];     }]; }

上面的代码就大致手动实现了UIModalTransitionStyleCrossDissolve的这个效果

前言

转场简单来说就是从一个VC转到另一个VC,系统提供了两大类转场方式:
1. NavigationControllerpush/pop
2. ViewControllerpresent(以前称为modal模态转场,老接口modalPresent被废弃了)

present系统模态转场

在讲解自定义转场前,先把系统封装好的模态转场弄懂

[presentingVC presentViewController: presentedVC animatd: YES completion: NULL]

很简单,presentingVC上弹出了presentedVC,但默认情况下(iPhone11+14)是这样的:

iOS 自定义转场

但实际上可以自己控制模态弹起的样式,UIViewController有两个属性可以选择不同样式:
1. modalPresentationStyle : 转场完成时的presentedVC的展示状态
2. modalTransitionStyle : 转场动画样式

要注意的是,这两个属性更改都要在presentedVC上才能生效

typedef NS_ENUM(NSInteger, UIModalTransitionStyle) {     UIModalTransitionStyleCoverVertical = 0, // 从屏幕下方弹出,默认且常用     UIModalTransitionStyleFlipHorizontal API_UNAVAILABLE(tvos), // 旋转门效果,比较丑     UIModalTransitionStyleCrossDissolve, // 应该是控制alpha变化,也比较常用     UIModalTransitionStylePartialCurl API_AVAILABLE(ios(3.2)) API_UNAVAILABLE(tvos), // 翻书样式,很丑 };
typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {     UIModalPresentationFullScreen = 0,     UIModalPresentationPageSheet ,     UIModalPresentationFormSheet ,     UIModalPresentationCurrentContext ,     UIModalPresentationCustom ,     UIModalPresentationOverFullScreen ,     UIModalPresentationOverCurrentContext ,     UIModalPresentationPopover ,     UIModalPresentationBlurOverFullScreen ,     UIModalPresentationNone API_AVAILABLE(ios(7.0)) = -1,     UIModalPresentationAutomatic API_AVAILABLE(ios(13.0)) = -2, };

presentStyle建议参考这篇博客

需要注意的是,虽然FullScreen是默认值,但在实际测试时(iphone 8/XR + 14)发现,在初始化ViewController后默认值是PageSheet,所以建议在present前显式的确定PresentationStyle


Present自定义转场

自定义转场主要参考了这一篇文章

最简单的自定义Present转场的实现我将其分为三部分实现:

1 设置presentedVC的transitioningDelegate

self.ctd = [ConfirmTransitionDelegate new]; PresentedViewController *pvc = [PresentedViewController new]; pvc.transitioningDelegate = self.ctd; [self presentViewController:pvc animated:YES completion:nil];

而ConfirmTransitionDelegate自然要遵循相应的协议UIViewControllerTransitioningDelegate:

UIViewControllerTransitioningDelegate里都是Optional,最简单的是实现以下两个代理方法:

- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {     return [CrossDissolveAnimator new]; }  - (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {     return [CrossDissolveAnimator new]; }

分别返回跳转和消失的AnimatorController(当然也可以返回不一样的Animator),下面实现CrossDissolveAnimator:

不过通常上presentedVC的transitioningDelegate都是presentingVC

 - (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {     return 0.25; }  - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {      UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];     UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];      UIView *fromView = nil;     UIView *toView = nil;     if ([transitionContext respondsToSelector:@selector(viewForKey:)]) {         fromView = [transitionContext viewForKey:UITransitionContextFromViewKey];         toView = [transitionContext viewForKey:UITransitionContextToViewKey];     } else {         fromView = fromVC.view;         toView = toVC.view;     }      UIView *containerView = transitionContext.containerView;      fromView.frame = [transitionContext initialFrameForViewController:fromVC];     toView.frame = [transitionContext finalFrameForViewController:toVC];      fromView.alpha = 1.0;     toView.alpha = 0;      [containerView addSubview:toView];      [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{         fromView.alpha = 0;         toView.alpha = 1.0;     } completion:^(BOOL finished) {         [transitionContext completeTransition:![transitionContext transitionWasCancelled]];     }]; }

上面的代码就大致手动实现了UIModalTransitionStyleCrossDissolve的这个效果

部分转自互联网,侵权删除联系

赞(0) 打赏
部分文章转自网络,侵权联系删除b2bchain区块链学习技术社区 » iOS 自定义转场求职学习资料
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

b2b链

联系我们联系我们