自定义present、dismiss转场动画的步骤和自定义push、pop转场动画的步骤是一致的,相关内容请看《iOS自定义转场动画-push和pop》。
主要涉及的API
push和pop自定义转场动画通过导航控制器的UINavigationControllerDelegate配置,而present和dismiss自定义转场动画通过控制器的本身属性transitioningDelegate(UIViewControllerTransitioningDelegate)配置。
下面是要用到UIViewControllerTransitioningDelegate的几个方法:
//指定present动画
- (nullable id )animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source;
//指定dismiss动画
- (nullable id )animationControllerForDismissedController:(UIViewController *)dismissed;
//指定交互式present动画的控制类
- (nullable id )interactionControllerForPresentation:(id )animator;
//指定交互式dismiss动画的控制类
- (nullable id )interactionControllerForDismissal:(id )animator;
present转场动画
1、准备工作:
ViewController类,要present到的下一级控制器SecondViewController类。
2、实现present动画:
这里演示的动画类似原生的push和pop动画,present时界面由右向左覆盖上一级界面,dismiss相反过程。
HSLeftPresentAnimation类定义:
@interface HSLeftPresentAnimation : NSObject
@property (nonatomic, assign) BOOL isPresent;
@end
为了方便我们将present和dismiss动画写在一起&