IOS動畫,ios動畫效果

來源:互聯網
上載者:User

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.