IOS各种简单动画的实现

#import "ViewController.h"

#import "aaViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

    

    [super viewDidLoad];

    

    UIView *magentaView = [[UIView alloc]initWithFrame:self.view.bounds];

    magentaView.backgroundColor = [UIColor magentaColor];

    [self.view addSubview:magentaView];

    

    UIView *grayView = [[UIView alloc]initWithFrame:self.view.bounds];

    grayView.backgroundColor = [UIColor lightGrayColor];

    [self.view addSubview:grayView];

    

    NSArray *bnTitleArray = [NSArray arrayWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",nil];

    NSMutableArray *bnArray = [[NSMutableArray alloc]init];

    CGFloat totalHeight = [UIScreen mainScreen].bounds.size.height;

    for (int i = 0; i<8; i++) {

        

        UIButton *bn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

        [bn setTitle:[bnTitleArray objectAtIndex:i] forState:UIControlStateNormal];

        NSInteger row = i/4;

        NSInteger col = i%4;

        bn.frame = CGRectMake(5+col*80,totalHeight-(2-row)*45-20,70,35);

        [self.view addSubview:bn];

        [bnArray addObject:bn];

        

    }

    

    [[bnArray objectAtIndex:0]addTarget:self action:@selector(add:) forControlEvents:UIControlEventTouchUpInside];

    [[bnArray objectAtIndex:1]addTarget:self action:@selector(curl:) forControlEvents:UIControlEventTouchUpInside];

    [[bnArray objectAtIndex:2]addTarget:self action:@selector(move:) forControlEvents:UIControlEventTouchUpInside];

    [[bnArray objectAtIndex:3]addTarget:self action:@selector(reveal:) forControlEvents:UIControlEventTouchUpInside];

    [[bnArray objectAtIndex:4]addTarget:self action:@selector(cube:) forControlEvents:UIControlEventTouchUpInside];

    [[bnArray objectAtIndex:5]addTarget:self action:@selector(suck:) forControlEvents:UIControlEventTouchUpInside];

    [[bnArray objectAtIndex:6]addTarget:self action:@selector(oglFlip:) forControlEvents:UIControlEventTouchUpInside];

    [[bnArray objectAtIndex:7]addTarget:self action:@selector(ripple:) forControlEvents:UIControlEventTouchUpInside];




 

}


-(void)add:(id)sender

{

    //开始执行动画

    [UIView beginAnimations:@"animation" context:nil];

    [UIView setAnimationDuration:1.0f];

    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    [self.view exchangeSubviewAtIndex:3 withSubviewAtIndex:2];

    [UIView commitAnimations];



}



-(void)curl:(id)sender

{

    //开始执行动画

    [UIView beginAnimations:@"animation" context:nil];

    [UIView setAnimationDuration:1.0f];

    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    [self.view exchangeSubviewAtIndex:3 withSubviewAtIndex:2];

    [UIView commitAnimations];

    

}


-(void)move:(id)sender

{


    CATransition *transition = [CATransition animation];

    transition.duration = 2.0f;

    transition.type = kCATransitionMoveIn;

    transition.subtype = kCATransitionFromLeft;

    [self.view.layer addAnimation:transition forKey:@"animation"];

    [self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:3];

}


-(void)reveal:(id)sender

{

    

    CATransition *transition = [CATransition animation];

    transition.duration = 2.0f;

    transition.type = kCATransitionReveal;

    transition.subtype = kCATransitionFromTop;

    [self.view.layer addAnimation:transition forKey:@"animation"];

    [self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:3];

}



-(void)cube:(id)sender

{

    

    CATransition *transition = [CATransition animation];

    transition.duration = 2.0f;

    transition.type = @"cube";

    transition.subtype = kCATransitionFromLeft;

    [self.view.layer addAnimation:transition forKey:@"animation"];

    [self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:3];

}



-(void)suck:(id)sender

{

    

    CATransition *transition = [CATransition animation];

    transition.duration = 2.0f;

    transition.type = @"suckEffect";

//    transition.subtype = kCATransitionFromLeft;

    [self.view.layer addAnimation:transition forKey:@"animation"];

    [self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:3];

}



-(void)oglFlip:(id)sender

{

    

    CATransition *transition = [CATransition animation];

    transition.duration = 2.0f;

    transition.type = @"oglFlip";

    transition.subtype = kCATransitionFromBottom;

    [self.view.layer addAnimation:transition forKey:@"animation"];

    [self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:3];

}


-(void)ripple:(id)sender

{

    //水波滑动

    [UIView animateWithDuration:4.0 animations:^{

        

        CATransition *transition = [CATransition animation];

        transition.duration = 4.0f;

        transition.type = @"rippleEffect";

        [self.view.layer addAnimation:transition forKey:@"animation"];

        transition.delegate = self;

        

        [self.view.layer addAnimation:transition forKey:nil];


  

    } completion:^(BOOL finished){

        [NSTimer timerWithTimeInterval:2.0 target:self selector:@selector(timee:) userInfo:nil repeats:NO];

        

    }];


}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值