美文网首页
关于自定义转场动画

关于自定义转场动画

作者: 吴冬 | 来源:发表于2016-08-10 14:01 被阅读18次

1. 首先被push的VC要签订 <UINavigationControllerDelegate>

2.实现协议方法- (nullable id <UINavigationControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController   animationControllerForOperation:(UINavigationControllerOperation)operation  fromViewController:(UIViewController *)fromVC  toViewController:(UIViewController *)toVC

{

   //在这里返回一个UINavigationControllerAnimatedTransitioning的实例

NSObject<UINavigationControllerAnimatedTransitioning>animated;

animated = [Animator alloc] init];

return animated;

}

3.实现Animator类

     3.1 首先Animator 遵循代理方法<UINavigationControllerAnimatedTransitioning>

     3.2 实现代理方法

          3.2.1 - (NSTimeInterval)transitionDuration: 

               (id<UINavigationControllerAnimatedTransitioning>)transitionContext

                 {

                     //动画时间 

                     return ANIMATION_TIME;

                 }

             3.2.2 - (void)animationTransition:  

                (id<UINavigationControllerAnimatedTransitioning>)transitionContext

                {

                       //transitionContext 上下文

                          UIView *container = [transitionContext containerView];

                       //获取当前VC

                         UIViewController *fromVC = [transitionContext   

                            viewControllerForKey:UITransitionContextFromViewControllerKey];

                      //获取要pop到的VC

                        UIViewController *toVC  = [transitionContext

                            viewControllerForKey:UITransitionContextToViewControllerKey];

                      //自己实现的转场动画.............

                      //结束完成转场

                      [transitionContext completeTransition:YES];

                 }


//常用到的方法

//7.0后的新方法,截取一段自定义大小的当前屏幕显示的VIEW ,可设置偏移量。 afterUpdates(个人理解:参数如果为NO,直接截取当前选中VIEW,如果为YES,会等当前选中的VIEW刷新到最新状态时候在更新)

- (UIView *)resizableSnapshotViewFromRect:(CGRect )rect  afterScreenUpdates:(BOOL)afterUpdates  withCapInsets:(UIEdgeInsets)capInsets;  NS_AVAILABLE_IOS(7_0)

           

相关文章

网友评论

      本文标题:关于自定义转场动画

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