使用系统的动画(点击切换界面)

来源:互联网 发布:淘宝游戏包 编辑:程序博客网 时间:2024/06/08 15:14

动画的类型

// kCATransitionFade 淡化

    // kCATransitionPush 推挤

    // kCATransitionReveal 揭开

    // kCATransitionMoveIn 覆盖

    // @“cube” 立方体  

    // @"suckEffect" 吸收

    // @"oglFlip" 翻转

    // @"rippleEffect" 波纹

    // @"pageCurl" 翻页
    // @"pageUnCurl" 反翻页
    // @"cameraIrisHollowOpen" 镜头开

CATransition *animation = [CATransition animation];            animation.delegate = self; //代理
            animation.duration = 0.8f; //延迟时间
            
            animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
            //    动画类型
            animation.type = @"cube";
            //    立方体翻转方向
            animation.subtype = kCATransitionFromRight;
            //    获取要进行切换的两个视图的索引        
            NSInteger viewIndex = [[self.view subviews] indexOfObject:imageView2]; // 是第一个View1的子控件
            NSInteger userHelpIndex = [[self.view subviews] indexOfObject:imageView2];//是第二个View2的子控件
            imageView2.hidden = NO;//显示第二个子控件
            [self.view exchangeSubviewAtIndex:viewIndex withSubviewAtIndex:userHelpIndex]; //进行切换
            //view 是view1 与 View2 的父控件 (前提是两个子控件都一定要在layer图层上)
            [view.layer addAnimation:animation forKey:nil];