欢迎光临
我们一直在努力

KYPushTransition

建站超值云服务器,限时71元/月

KYPushTransition

项目介绍:

KYPushTransition

https://github.com/KittenYang/KYPushTransition

一个3D翻转的转场动画,可以手势百分比控制。

Usage

以下代码全在第一个视图控制器中实现:

进入第一个控制器。在跳转之前,设置后一个控制器的代理,比如我用Segue的话,就在-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender里设置后一个控制器的代理为前一个控制器,并且让后一个控制器实现手势返回的交互:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    
    SecondViewController *secVC = (SecondViewController *)segue.destinationViewController;
    secVC.transitioningDelegate = self;
    popInteractive = [KYPopInteractiveTransition new];
    [popInteractive addPopGesture:secVC];
}

然后分两种情况:

1)如果只是一个VC present 到另一个 VC,那么你需要实现UIViewControllerTransitioningDelegate中的两个协议,分别对应presentdismiss,返回对应的动画:

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source{
    
    KYPushTransition *flip = [KYPushTransition new];

    return flip;
}

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed{
    KYPopTransition *flip = [KYPopTransition new];
    return flip;
    
}

然后是手势交互的方法,比较常用的情况是返回上一个VC采用手势,所以这里只实现了dismiss的方法:

- (id <UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id <UIViewControllerAnimatedTransitioning>)animator{
    return popInteractive.interacting ? popInteractive : nil;
    
}

2)如果你是用UINavigationController控制两个VC,那么需要实现UINavigationControllerDelegate中的:

- (id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
                                   animationControllerForOperation:(UINavigationControllerOperation)operation
                                                fromViewController:(UIViewController *)fromVC
                                                  toViewController:(UIViewController *)toVC{
    if (operation == UINavigationControllerOperationPush) {
        
        KYPushTransition *flip = [KYPushTransition new];
        return flip;
        
    }else if (operation == UINavigationControllerOperationPop){
        
        KYPopTransition *flip = [KYPopTransition new];
        return flip;
        
    }else{
        return nil;
    }
}

UINaviagtionController控制VC的情况下,UINavigationControllerDelegate也有相应的手势交互的协议方法:

- (id <UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController
                          interactionControllerForAnimationController:(id <UIViewControllerAnimatedTransitioning>) animationController{
        return popInteractive.interacting ? popInteractive : nil;

点击博客介绍阅读详细实现细节

code4app

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » KYPushTransition
分享到: 更多 (0)