• (素材源码)猫猫学iOS(四十一)UI之核心动画 两行代码搞定3D转场(做android的哭死)


    猫猫分享,必须精品

    原创文章,欢迎转载。转载请注明:翟乃玉的博客
    地址:http://blog.csdn.net/u013357243?viewmode=contents
    源码素材地址:http://download.csdn.net/detail/u013357243/8677065

    效果:

    这里写图片描述

    代码:

    
    
    #import "NYViewController.h"
    
    @interface NYViewController ()
    @property (weak, nonatomic) IBOutlet UIImageView *iconView;
    - (IBAction)nextBtnClick:(id)sender;
    - (IBAction)preBtnClick:(id)sender;
    
    @property (nonatomic, assign) int index;
    @end
    
    @implementation NYViewController
    
    // 下一张
    - (IBAction)nextBtnClick:(id)sender {
        self.index++;
        if (self.index >7) {
            self.index = 1;
        }
    
        NSString *imageName = [NSString stringWithFormat:@"%d.jpg", self.index];
        UIImage *newImage = [UIImage imageNamed:imageName];
        self.iconView.image = newImage;
    
        // 1.创建核心动画
        CATransition *ca = [CATransition animation];
        // 1.1动画过渡类型
        ca.type = @"cube";
        // 1.2动画过渡方向
        ca.subtype =  kCATransitionFromRight;
        // 1.3动画起点(在整体动画的百分比)
        //ca.startProgress = 0.5;
        //1.3动画终点(在整体动画的百分比)
        //ca.endProgress = 0.5;
    
    
        // 动画时间
        ca.duration = 1;
    
        // 2.添加核心动画
        [self.iconView.layer addAnimation:ca forKey:nil];
    }
    
    // 上一张
    - (IBAction)preBtnClick:(id)sender {
        self.index--;
        if (self.index < 1) {
            self.index = 7;
        }
        NSString *imageName = [NSString stringWithFormat:@"%d.jpg", self.index];
        UIImage *newImage = [UIImage imageNamed:imageName];
        self.iconView.image = newImage;
    
        // 1.创建核心动画
        CATransition *ca = [CATransition animation];
        // 1.1告诉系统执行什么动画
        ca.type = @"cube";
        ca.subtype =  kCATransitionFromLeft;
    
        ca.duration = 1;
    
        // 2.添加核心动画
        [self.iconView.layer addAnimation:ca forKey:nil];
    
    }
    @end
    
    
    
  • 相关阅读:
    SpringBoot配置文件
    SpringBoot基础开发流程
    day06-01数字类型、数字类型的转换
    特有的循环结构(for-else、while-else)——Python篇
    分支、循环——Python基础篇
    循环关键字——Python篇
    另类三目运算符——Python篇
    原码、反码以及补码
    Python运算符
    Python变量
  • 原文地址:https://www.cnblogs.com/znycat/p/4521006.html
Copyright © 2020-2023  润新知