iOS 自定义转场动画(push)

一:用一个枚举定义动画类型:

typedef enum{
    rippleEffect = 0, //波纹效果
    cube,//立体翻转效果
    suckEffect,//像被吸入瓶子的效果
    oglflip,//翻转
    pageCurl,//翻页效果
    pageUnCurl,//反翻页效果
    cameraIrisHollowOpen,//开镜头效果
    cameraIrisHollowClose,//关镜头效果
    fade,//淡入淡出
    push,//推进效果
    reveal,//揭开效果
    moveIn,//慢慢进入并覆盖效果
    fromBottom,//下翻页效果
    fromTop,//上翻页效果
    fromLeft,//左翻转效果
    fromRight//右翻转效果
} PushControllerAnimation;

2:工具类里面封装此方法(ToolObject)

#pragma - mark - 页面跳转动画
+ (CATransition *)pushAnimationWith:(PushControllerAnimation)animation fromController:(id)delegate {
    CATransition * transition = [CATransition animation];
    transition.duration = 0.25f;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    switch (animation) {
        case 0:
            transition.type = @"rippleEffect";
            break;
        case 1:
            transition.type = @"cube";
            break;
        case 2:
            transition.type = @"suckEffect";
            break;
        case 3:
            transition.type = @"oglflip";
            break;
        case 4:
            transition.type = @"pageCurl";
            break;
        case 5:
            transition.type = @"pageUnCurl";
            break;
        case 6:
            transition.type = @"cameraIrisHollowOpen";
            break;
        case 7:
            transition.type = @"cameraIrisHollowClose";
            break;
        case 8:
            transition.type = @"fade";
            break;
        case 9:
            transition.type = @"push";
            break;
        case 10:
            transition.type = @"reveal";
            break;
        case 11:
            transition.type = @"moveIn";
            break;
        case 12:
            transition.type = @"fromBottom";
            break;
        case 13:
            transition.type = @"fromTop";
            break;
        case 14:
            transition.type = @"fromLeft";
            break;
        case 15:
            transition.type = @"fromRight";
            break;
        default:
            break;
    }
    transition.subtype = kCATransitionMoveIn;
    transition.delegate = delegate;
    return transition;
}

3:控制器调用此方法

    //淡入淡出push效果
    CATransition *transition = [ToolObject pushAnimationWith:fade fromController:self.viewController];
    transition.delegate = (id)self.viewController;
    [self.viewController.navigationController.view.layer addAnimation:transition forKey:nil];

    UIViewController *vc = [[UIViewController alloc] init];
    [self.navigationController pushViewController:vc animated:NO];
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值