天天看点

视图控制器转场动画——CATransition

github:https://github.com/potato512/SYAnimation

使用CATransition进行视图控制器的转场动画自定义。

效果图:

视图控制器转场动画——CATransition

代码示例:

// 转场动画
    CATransition *animation = [CATransition animation];
    animation.duration = 0.6;
    animation.fillMode = kCAFillModeForwards;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
    // 转场效果-动画类型type 动画方向subtype
    if (0 == indexPath.row)
    {
        animation.type = @"cube";
        animation.subtype = kCATransitionFromLeft;
    }
    else if (1 == indexPath.row)
    {
        animation.type = @"moveIn";
        animation.subtype = kCATransitionFromLeft;
    }
    else if (2 == indexPath.row)
    {
        animation.type = @"reveal";
        animation.subtype = kCATransitionFromLeft;
    }
    else if (3 == indexPath.row)
    {
        animation.type = @"fade";
        animation.subtype = kCATransitionFromLeft;
    }
    else if (4 == indexPath.row)
    {
        animation.type = @"pageCurl";
        animation.subtype = kCATransitionFromLeft;
    }
    else if (5 == indexPath.row)
    {
        animation.type = @"pageUnCurl";
        animation.subtype = kCATransitionFromRight;
    }
    else if (6 == indexPath.row)
    {
        animation.type = @"suckEffect";
        animation.subtype = kCATransitionFromLeft;
    }
    else if (7 == indexPath.row)
    {
        animation.type = @"rippleEffect";
        animation.subtype = kCATransitionFromLeft;
    }
    else if (8 == indexPath.row)
    {
        animation.type = @"oglFlip";
        animation.subtype = kCATransitionFromLeft;
    }
    else if (9 == indexPath.row)
    {
        animation.type = @"rotate";
        animation.subtype = @"90cw";
    }
    else if (10 == indexPath.row)
    {
        animation.type = @"push";
        animation.subtype = kCATransitionFromLeft;
    }
    else if (11 == indexPath.row)
    {
        animation.type = @"cameraIrisHollowOpen";
        animation.subtype = kCATransitionFromLeft;
    }
    else if (12 == indexPath.row)
    {
        animation.type = @"cameraIrisHollowClose";
        animation.subtype = kCATransitionFromLeft;
    }
    else if (13 == indexPath.row)
    {
        animation.type = @"kCATransitionFade";
        animation.subtype = kCATransitionFromLeft;
    }
    else if (14 == indexPath.row)
    {
        animation.type = @"kCATransitionMoveIn";
        animation.subtype = kCATransitionFromLeft;
    }
    else if (15 == indexPath.row)
    {
        animation.type = @"kCATransitionPush";
        animation.subtype = kCATransitionFromLeft;
    }
    else if (16 == indexPath.row)
    {
        animation.type = @"kCATransitionReveal";
        animation.subtype = kCATransitionFromLeft;
    }
    // 添加转场动画到导航视图控制上
    [self.navigationController.view.layer addAnimation:animation forKey:nil];