OC_转场动画的实现

参考文章:https://blog.csdn.net/qq_19678579/article/details/51519757
先认识几个关键类

  • UIViewControllerAnimatedTransitioning: 实现动画转场的协议
@protocol UIViewControllerAnimatedTransitioning 
// 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 )transitionContext;
// This method can only  be a nop if the transition is interactive and not a percentDriven interactive transition.

- (void)animateTransition:(id )transitionContext;
  • UIViewControllerInteractiveTransitioning :实现交互转场的协议,主要用到与手势交互
@protocol UIViewControllerInteractiveTransitioning 
- (void)startInteractiveTransition:(id )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 

/// 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 )navigationController:(UINavigationController *)navigationController
                                   animationControllerForOperation:(UINavigationControllerOperation)operation
                                                fromViewController:(UIViewController *)fromVC
                                                  toViewController:(UIViewController *)toVC  NS_AVAILABLE_IOS(7_0);

你可能感兴趣的:(OC_转场动画的实现)