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

本文介绍了如何使用CATransition创建视图控制器间的转场动画,并提供了代码示例,展示了自定义转场动画的效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

githubhttps://github.com/potato512/SYAnimation

使用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];



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

番薯大佬

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值