IOS动画

IOS动画

//
//  ViewController.m
//  IOS-动画特效
//
//  Created by wangtouwang on 15/5/5.
//  Copyright (c) 2015年 wangtouwang. All rights reserved.
//

#import "ViewController.h"
#define kDuration 0.7   // 动画持续时间(秒)
#define KS_HEIGTH [UIScreen mainScreen].bounds.size.height
#define KS_WIDTH  [UIScreen mainScreen].bounds.size.Width

@interface ViewController ()

@property(nonatomic,strong) UIView *imageView;

@end

@implementation ViewController
@synthesize typeID;
@synthesize blueView;
@synthesize greenView;

-(void)animationFunction:(UIButton *)btn{
    NSInteger index =  btn.tag;
    CATransition *transition = [CATransition animation];
    //代理
    transition.delegate = self;
    //持续时间
    transition.duration= kDuration;
    //类型
    transition.type = [self getAnimationType:index];
    //方向
    transition.subtype = [self getSubType];
    // 动画的开始与结束的快慢*/
    transition.timingFunction = UIViewAnimationCurveEaseInOut;
    //事件源
    NSInteger blue = [[_imageView subviews] indexOfObject:blueView];
    NSInteger green = [[_imageView subviews] indexOfObject:greenView];
    [_imageView exchangeSubviewAtIndex:green withSubviewAtIndex:blue];
    
    //开始动画
    [_imageView.layer addAnimation:transition forKey:@"animation"];
}


-(void)animationFunction2:(UIButton *)btn{
    NSInteger index =  btn.tag;
    CGContextRef context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];//开始一个动画块
    [UIView setAnimationDelegate:self];//代理
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//设置动画块中的动画属性变化的曲线。
    [UIView setAnimationDuration:kDuration];//在动画块中设置动画的延迟属性 (以秒为单位)
   //在动画块中为视图设置过渡
    switch (index) {
        case 10:
            [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
            break;
        case 9:
            [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
            break;
        case 12:
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
            break;
        case 11:
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
            break;
        default:
            break;
    }
    //事件源
    NSInteger blue = [[_imageView subviews] indexOfObject:blueView];
    NSInteger green = [[_imageView subviews] indexOfObject:greenView];
    [_imageView exchangeSubviewAtIndex:green withSubviewAtIndex:blue];
    
    // 动画完毕后调用某个方法
    //[UIView setAnimationDidStopSelector:@selector(animationFinished:)];
    [UIView commitAnimations];//结束一个动画块并开始当他在动画块外时
}

-(NSString *)getAnimationType:(NSInteger)index{
    NSString *type=nil;
    switch (index) {
        case 5:
            type = kCATransitionFade;
            break;
        case 6:
            type = kCATransitionPush;
            break;
        case 7:
            type = kCATransitionReveal;
            break;
        case 8:
            type = kCATransitionMoveIn;
            break;
        case 4:
            type = @"cube";
            break;
        case 3:
            type = @"suckEffect";
            break;
        case 1:
            type = @"pageCurl";
            break;
        case 2:
            type = @"pageUnCurl";
            break;
        default:
            break;
    }

    return type;
}



-(NSString *)getSubType{
    NSString *subtype = nil;
    switch (self.typeID) {
        case 0:
            subtype = kCATransitionFromLeft;
            break;
        case 1:
            subtype = kCATransitionFromBottom;
            break;
        case 2:
            subtype = kCATransitionFromRight;
            break;
        case 3:
            subtype = kCATransitionFromTop;
            break;
        default:
            break;
    }
    self.typeID += 1;
    if (self.typeID > 3) {
        self.typeID = 0;
    }
    return subtype;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self.navigationItem setTitle:@"动画特效"];
    
    UIButton *addBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(10,70, 80, 30)];
    [addBtn1 setTitle:@"翻页" forState:UIControlStateNormal];
    addBtn1.titleLabel.font=[UIFont systemFontOfSize:13.0f];
    [addBtn1 setBackgroundColor:[UIColor grayColor]];
    addBtn1.tag=1;
    [addBtn1 addTarget:self action:@selector(animationFunction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addBtn1];
    
    UIButton *addBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(100,70, 80, 30)];
    [addBtn2 setTitle:@"反翻页" forState:UIControlStateNormal];
    addBtn2.titleLabel.font=[UIFont systemFontOfSize:13.0f];
    [addBtn2 setBackgroundColor:[UIColor grayColor]];
    addBtn2.tag=2;
    [addBtn2 addTarget:self action:@selector(animationFunction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addBtn2];
    
    UIButton *addBtn3 = [[UIButton alloc] initWithFrame:CGRectMake(190,70, 80, 30)];
    [addBtn3 setTitle:@"波纹" forState:UIControlStateNormal];
    addBtn3.titleLabel.font=[UIFont systemFontOfSize:13.0f];
    [addBtn3 setBackgroundColor:[UIColor grayColor]];
    addBtn3.tag=3;
    [addBtn3 addTarget:self action:@selector(animationFunction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addBtn3];
    
    UIButton *addBtn4 = [[UIButton alloc] initWithFrame:CGRectMake(280,70, 80, 30)];
    [addBtn4 setTitle:@"立方体" forState:UIControlStateNormal];
    addBtn4.titleLabel.font=[UIFont systemFontOfSize:13.0f];
    [addBtn4 setBackgroundColor:[UIColor grayColor]];
    addBtn4.tag=4;
    [addBtn4 addTarget:self action:@selector(animationFunction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addBtn4];
    
    UIButton *addBtn5 = [[UIButton alloc] initWithFrame:CGRectMake(10,110, 80, 30)];
    [addBtn5 setTitle:@"淡化" forState:UIControlStateNormal];
    addBtn5.titleLabel.font=[UIFont systemFontOfSize:13.0f];
    [addBtn5 setBackgroundColor:[UIColor grayColor]];
    addBtn5.tag=5;
    [addBtn5 addTarget:self action:@selector(animationFunction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addBtn5];
    
    UIButton *addBtn6 = [[UIButton alloc] initWithFrame:CGRectMake(100,110, 80, 30)];
    [addBtn6 setTitle:@"推挤" forState:UIControlStateNormal];
    addBtn6.titleLabel.font=[UIFont systemFontOfSize:13.0f];
    [addBtn6 setBackgroundColor:[UIColor grayColor]];
    addBtn6.tag=6;
    [addBtn6 addTarget:self action:@selector(animationFunction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addBtn6];
    
    UIButton *addBtn7 = [[UIButton alloc] initWithFrame:CGRectMake(190,110, 80, 30)];
    [addBtn7 setTitle:@"揭开" forState:UIControlStateNormal];
    addBtn7.titleLabel.font=[UIFont systemFontOfSize:13.0f];
    [addBtn7 setBackgroundColor:[UIColor grayColor]];
    addBtn7.tag=7;
    [addBtn7 addTarget:self action:@selector(animationFunction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addBtn7];
    
    UIButton *addBtn8 = [[UIButton alloc] initWithFrame:CGRectMake(280,110, 80, 30)];
    [addBtn8 setTitle:@"覆盖" forState:UIControlStateNormal];
    addBtn8.titleLabel.font=[UIFont systemFontOfSize:13.0f];
    [addBtn8 setBackgroundColor:[UIColor grayColor]];
    addBtn8.tag=8;
    [addBtn8 addTarget:self action:@selector(animationFunction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addBtn8];
    
    
    UIButton *addBtn9 = [[UIButton alloc] initWithFrame:CGRectMake(10,150, 80, 30)];
    [addBtn9 setTitle:@"上翻" forState:UIControlStateNormal];
    addBtn9.titleLabel.font=[UIFont systemFontOfSize:13.0f];
    [addBtn9 setBackgroundColor:[UIColor grayColor]];
    addBtn9.tag=9;
    [addBtn9 addTarget:self action:@selector(animationFunction2:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addBtn9];
    
    UIButton *addBtn10 = [[UIButton alloc] initWithFrame:CGRectMake(100,150, 80, 30)];
    [addBtn10 setTitle:@"下翻" forState:UIControlStateNormal];
    addBtn10.titleLabel.font=[UIFont systemFontOfSize:13.0f];
    [addBtn10 setBackgroundColor:[UIColor grayColor]];
    addBtn10.tag=10;
    [addBtn10 addTarget:self action:@selector(animationFunction2:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addBtn10];
    
    UIButton *addBtn11 = [[UIButton alloc] initWithFrame:CGRectMake(190,150, 80, 30)];
    [addBtn11 setTitle:@"左翻" forState:UIControlStateNormal];
    addBtn11.titleLabel.font=[UIFont systemFontOfSize:13.0f];
    [addBtn11 setBackgroundColor:[UIColor grayColor]];
    addBtn11.tag=11;
    [addBtn11 addTarget:self action:@selector(animationFunction2:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addBtn11];
    
    UIButton *addBtn12 = [[UIButton alloc] initWithFrame:CGRectMake(280,150, 80, 30)];
    [addBtn12 setTitle:@"右翻" forState:UIControlStateNormal];
    addBtn12.titleLabel.font=[UIFont systemFontOfSize:13.0f];
    [addBtn12 setBackgroundColor:[UIColor grayColor]];
    addBtn12.tag=12;
    [addBtn12 addTarget:self action:@selector(animationFunction2:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addBtn12];
    
    
    _imageView = [[UIView alloc] initWithFrame:CGRectMake(0, 190, [UIScreen mainScreen].bounds.size.width, KS_HEIGTH-190)];
    [self.view addSubview:_imageView];
    
    blueView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"XXX_123.png"]];
    blueView.frame=CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, KS_HEIGTH-150);
    [_imageView addSubview:blueView];
    
    greenView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"XXX_321.png"]];
    greenView.frame=CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, KS_HEIGTH-150);
    [_imageView addSubview:greenView];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}




@end

IOS动画

IOS动画

转载于:https://www.cnblogs.com/ak23173969/p/4481165.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/109462.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • vue实现上传文件_vue工程如何打包部署运行

    vue实现上传文件_vue工程如何打包部署运行SpringMVC+vue实现文件上传后台前端异步上传(后端springmvc加前端vue)后台采用springmvc,实现获取到相对路径和绝对路径存储为json传到前端作为新增到数据库里的数据//文件上传@PostMapping(value=”/upLoading”)@ResponseBodypublicResult<HashMap<String,String>>upLoading(MultipartFilefile,Http

    2022年8月15日
    4
  • 一道线程同步面试题

    一道线程同步面试题

    2021年11月13日
    38
  • linux 驱动移植_免驱动led灯好吗

    linux 驱动移植_免驱动led灯好吗通过前两篇文章的介绍,我们已经把linux内核移植到了tiny210上,但是看到的现象都是通过超级终端来观察的,下面了,我们介绍一下led灯的移植,给大家一个更直观的感受。这篇文章主要的内容如下:1.对平台总线的简介;2.led驱动的移植。一.平台总线   首先介绍一下,我们为什么要简单介绍一下平台总线呢?因为我们是做led驱动的移植,而不是自己编写led的驱动代码。我们要移植

    2022年9月25日
    0
  • laravel报404错误与NGINX报404错误区别

    laravel报404错误与NGINX报404错误区别

    2021年11月6日
    46
  • 高斯约尔当法求逆矩阵_高斯约当消元法求逆矩阵

    高斯约尔当法求逆矩阵_高斯约当消元法求逆矩阵介绍了求逆矩阵方法,并附带java与python语言实现

    2022年8月21日
    6
  • 时序数据库应用_tsdb时序数据库

    时序数据库应用_tsdb时序数据库前言mysql可能大家都用的比较多且普遍,最近1年在使用PostgreSql,其大体DML语句与mysql类似,只是部分DDL语句有些区别,写一篇文章给正在应用该数据库或者准备选型该数据库的朋友,分享下使用方式与心得PostgreSqlPostgreSQL是一种特性非常齐全的自由软件的对象-关系型数据库管理系统(ORDBMS),是以加州大学计算机系开发的POSTGRES,4.2版本为基础的对象关系型数据库管理系统。POSTGRES的许多领先概念只是在比较迟的时候才…

    2022年9月27日
    1

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号