#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];
}];
}