美文网首页
OC_转场动画的实现

OC_转场动画的实现

作者: 走停2015_iOS开发 | 来源:发表于2018-05-08 15:28 被阅读7次

    参考文章: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);
    

    相关文章

      网友评论

          本文标题:OC_转场动画的实现

          本文链接:https://www.haomeiwen.com/subject/ldqwrftx.html