#import "ViewController.h"
#import "QuartzCore/QuartzCore.h"
@interface ViewController ()
{
UIButton *box ;
UIButton *box2 ;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor blackColor];
box = [UIButton buttonWithType:UIButtonTypeRoundedRect];
box.frame= CGRectMake(0,0,50,50);
[box setTitle:@"hello" forState:UIControlStateApplication];
//box.titleLabel.text = @"hello";
// box = [[UIView alloc]initWithFrame:CGRectMake(10,10,50,50)];
box.backgroundColor = [UIColor yellowColor];
box2= [UIButton buttonWithType:UIButtonTypeRoundedRect];
box2.frame= CGRectMake(0,0,50,50);
[box2 setTitle:@"hello" forState:UIControlStateApplication];
//box.titleLabel.text = @"hello";
// box = [[UIView alloc]initWithFrame:CGRectMake(10,10,50,50)];
box2.backgroundColor = [UIColor yellowColor];
[self.view addSubview: box];
[self.view addSubview: box2];
/**
CABasicAnimation *animation = [CABasicAnimation animation];
animation.toValue = (id)[UIColor blueColor].CGColor;
animation.duration = 1;
animation.autoreverses = YES;
[self.view.layer addAnimation:animation forKey:@"backgroundColor"];
*/
/**
CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
animation.values = [NSArray arrayWithObjects:
//(id)self.view.backgroundColor,
(id)[UIColor yellowColor].CGColor,
(id)[UIColor greenColor].CGColor,
(id)[UIColor blueColor].CGColor,
nil];
animation.duration = 4;
animation.autoreverses = YES;
[self.view.layer addAnimation:animation forKey:@"backgroundColor"];
*/
// [box release];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)go:(UIButton *)sender {
}
- (IBAction)animalTest:(UIButton *)sender {
/**
[UIView beginAnimations:@"box-animation" context:nil];
[UIView setAnimationDuration:1];
box.backgroundColor = [UIColor redColor];
box.frame = CGRectMake(50, 50, 200, 100);
box.alpha = 0.5;
[UIView commitAnimations];
*/
/**
CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
// animation.repeatCount=100;
CGMutablePathRef apath = CGPathCreateMutable();
CGPathMoveToPoint(apath, nil, 20, 20);//move to start point
CGPathAddCurveToPoint(apath, nil, 160, 30, 220, 220, 300, 30);
animation.path =apath;
animation.duration = 2;
animation.timingFunction = [ CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear];
animation.rotationMode = kCAAnimationRotateAutoReverse;//kCAAnimationRotateAuto;
//animation.autoreverses = YES;
CAKeyframeAnimation *animation2 = [CAKeyframeAnimation animation];
// animation2.repeatCount=100;
animation2.path =apath;
animation2.duration = 2;
animation2.timingFunction = [ CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear];
animation2.rotationMode = kCAAnimationRotateAuto;//kCAAnimationRotateAuto;
//animation2.autoreverses = YES;
[box.layer addAnimation:animation forKey:@"position"];
[box2.layer addAnimation:animation2 forKey:@"position"];
CFRelease(apath) ;
*/
//创建Y轴旋转动画
CABasicAnimation *flip = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
flip.toValue = [NSNumber numberWithDouble:3.14];
// flip.autoreverses = YES;
//缩放动画
CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scale.toValue = [NSNumber numberWithDouble:.5];
scale.duration = 0.5;
scale.autoreverses = YES;
//将缩放动画与反转动画合成
CAAnimationGroup *group = [CAAnimationGroup animation];
group .animations = [NSArray arrayWithObjects:flip,scale, nil];
group.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut] ;
group.duration = 1;
// group.autoreverses = YES;
group.fillMode = kCAFillModeForwards;
group.removedOnCompletion = NO ;
[self.view.layer addAnimation:group forKey:@"flip"];
}
@end