参考文章:https://blog.csdn.net/qq_19678579/article/details/51519757
先认识几个关键类
-
UIViewControllerAnimatedTransitioning
: 实现动画转场的协议
@protocol UIViewControllerAnimatedTransitioning <NSObject>
// This is used for percent driven interactive transitions, as well as for
// container controllers that have companion animations that might need to
// synchronize with the main animation.
- (NSTimeInterval)transitionDuration:(nullable id <UIViewControllerContextTransitioning>)transitionContext;
// This method can only be a nop if the transition is interactive and not a percentDriven interactive transition.
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext;
-
UIViewControllerInteractiveTransitioning
:实现交互转场的协议,主要用到与手势交互
@protocol UIViewControllerInteractiveTransitioning <NSObject>
- (void)startInteractiveTransition:(id <UIViewControllerContextTransitioning>)transitionContext;
@optional
#if UIKIT_DEFINE_AS_PROPERTIES
@property(nonatomic, readonly) CGFloat completionSpeed;
@property(nonatomic, readonly) UIViewAnimationCurve completionCurve;
#else
- (CGFloat)completionSpeed;
- (UIViewAnimationCurve)completionCurve;
#endif
-
UIPercentDrivenInteractiveTransition
: 继承NSObject 遵守UIViewControllerInteractiveTransitioning
的类
NS_CLASS_AVAILABLE_IOS(7_0) @interface UIPercentDrivenInteractiveTransition : NSObject <UIViewControllerInteractiveTransitioning>
/// This is the non-interactive duration that was returned when the
/// animators transitionDuration: method was called when the transition started.
@property (readonly) CGFloat duration;
/// The last percentComplete value specified by updateInteractiveTransition:
@property (readonly) CGFloat percentComplete;
/// completionSpeed defaults to 1.0 which corresponds to a completion duration of
/// (1 - percentComplete)*duration. It must be greater than 0.0. The actual
/// completion is inversely proportional to the completionSpeed. This can be set
/// before cancelInteractiveTransition or finishInteractiveTransition is called
/// in order to speed up or slow down the non interactive part of the
/// transition.
- 主要实现的
协议方法
-(nullable id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC NS_AVAILABLE_IOS(7_0);