OC_转场动画的实现

参考文章: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);
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容