IOS各种简单动画的实现

来源:互联网 发布:unity3d场景下载 编辑:程序博客网 时间:2024/06/01 09:41

#import "ViewController.h"

#import "aaViewController.h"


@interfaceViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

    

    [superviewDidLoad];

    

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

    magentaView.backgroundColor = [UIColormagentaColor];

    [self.viewaddSubview:magentaView];

    

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

    grayView.backgroundColor = [UIColorlightGrayColor];

    [self.viewaddSubview:grayView];

    

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

    NSMutableArray *bnArray = [[NSMutableArrayalloc]init];

    CGFloat totalHeight = [UIScreenmainScreen].bounds.size.height;

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

        

        UIButton *bn = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

        [bnsetTitle:[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.viewaddSubview:bn];

        [bnArray addObject:bn];

        

    }

    

    [[bnArrayobjectAtIndex:0]addTarget:selfaction:@selector(add:)forControlEvents:UIControlEventTouchUpInside];

    [[bnArrayobjectAtIndex:1]addTarget:selfaction:@selector(curl:)forControlEvents:UIControlEventTouchUpInside];

    [[bnArrayobjectAtIndex:2]addTarget:selfaction:@selector(move:)forControlEvents:UIControlEventTouchUpInside];

    [[bnArrayobjectAtIndex:3]addTarget:selfaction:@selector(reveal:)forControlEvents:UIControlEventTouchUpInside];

    [[bnArrayobjectAtIndex:4]addTarget:selfaction:@selector(cube:)forControlEvents:UIControlEventTouchUpInside];

    [[bnArrayobjectAtIndex:5]addTarget:selfaction:@selector(suck:)forControlEvents:UIControlEventTouchUpInside];

    [[bnArrayobjectAtIndex:6]addTarget:selfaction:@selector(oglFlip:)forControlEvents:UIControlEventTouchUpInside];

    [[bnArrayobjectAtIndex:7]addTarget:selfaction:@selector(ripple:)forControlEvents:UIControlEventTouchUpInside];




 

}


-(void)add:(id)sender

{

    //开始执行动画

    [UIViewbeginAnimations:@"animation"context:nil];

    [UIViewsetAnimationDuration:1.0f];

    [UIViewsetAnimationTransition:UIViewAnimationTransitionCurlDownforView:self.viewcache:YES];

    [UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];

    [self.viewexchangeSubviewAtIndex:3withSubviewAtIndex:2];

    [UIViewcommitAnimations];



}



-(void)curl:(id)sender

{

    //开始执行动画

    [UIViewbeginAnimations:@"animation"context:nil];

    [UIViewsetAnimationDuration:1.0f];

    [UIViewsetAnimationTransition:UIViewAnimationTransitionCurlUpforView:self.viewcache:YES];

    [UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];

    [self.viewexchangeSubviewAtIndex:3withSubviewAtIndex:2];

    [UIViewcommitAnimations];

    

}


-(void)move:(id)sender

{


    CATransition *transition = [CATransitionanimation];

    transition.duration =2.0f;

    transition.type =kCATransitionMoveIn;

    transition.subtype =kCATransitionFromLeft;

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

    [self.viewexchangeSubviewAtIndex:2withSubviewAtIndex:3];

}


-(void)reveal:(id)sender

{

    

    CATransition *transition = [CATransitionanimation];

    transition.duration =2.0f;

    transition.type =kCATransitionReveal;

    transition.subtype =kCATransitionFromTop;

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

    [self.viewexchangeSubviewAtIndex:2withSubviewAtIndex:3];

}



-(void)cube:(id)sender

{

    

    CATransition *transition = [CATransitionanimation];

    transition.duration =2.0f;

    transition.type =@"cube";

    transition.subtype =kCATransitionFromLeft;

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

    [self.viewexchangeSubviewAtIndex:2withSubviewAtIndex:3];

}



-(void)suck:(id)sender

{

    

    CATransition *transition = [CATransitionanimation];

    transition.duration =2.0f;

    transition.type =@"suckEffect";

//    transition.subtype = kCATransitionFromLeft;

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

    [self.viewexchangeSubviewAtIndex:2withSubviewAtIndex:3];

}



-(void)oglFlip:(id)sender

{

    

    CATransition *transition = [CATransitionanimation];

    transition.duration =2.0f;

    transition.type =@"oglFlip";

    transition.subtype =kCATransitionFromBottom;

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

    [self.viewexchangeSubviewAtIndex:2withSubviewAtIndex:3];

}


-(void)ripple:(id)sender

{

    //水波滑动

    [UIViewanimateWithDuration:4.0animations:^{

        

        CATransition *transition = [CATransitionanimation];

        transition.duration =4.0f;

        transition.type =@"rippleEffect";

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

        transition.delegate =self;

        

        [self.view.layeraddAnimation:transition forKey:nil];


  

    } completion:^(BOOL finished){

        [NSTimertimerWithTimeInterval:2.0target:selfselector:@selector(timee:)userInfo:nilrepeats:NO];

        

    }];


}


1 0
原创粉丝点击