//
// ViewController.m
// aaaaaaa
//
// Created by yubang on 14-6-17.
// Copyright (c) 2014年 yubang. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
{
UIButton *b;
int isfront;
UIImageView *imageView;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
isfront = 1;
b = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[b setBackgroundColor:[UIColor blackColor]];
[b setFrame:CGRectMake(100, 120, 100, 150)];
[self.view addSubview:b];
// [b addTarget:self action:@selector(testBase) forControlEvents:UIControlEventTouchUpInside];
UIButton *a;
a = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[a setBackgroundColor:[UIColor yellowColor]];
[a setFrame:CGRectMake(100, 120, 100, 150)];
[self.view addSubview:a];
a.tag = 10;
[a addTarget:self action:@selector(testBase) forControlEvents:UIControlEventTouchUpInside];
imageView = [[UIImageView alloc] initWithFrame:self.view.frame];
UIImage *image = [UIImage imageNamed:@"22.jpg"];
imageView.image = image;
[self.view addSubview:imageView];
}
- (void)testKeyFrameAnimation
{
CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
animation.keyPath = @"position.x";
animation.values = @[ @0, @10, @-10, @10, @0 ];
animation.keyTimes = @[ @0, @(1 / 6.0), @(2 /6.0),@(3 / 6.0), @(5 / 6.0), @1 ];
animation.duration = 0.5f;
animation.additive = YES;
[b.layer addAnimation:animation forKey:NULL];
}
- (void)testRoundKeyFrame
{
CGRect boundingRect = CGRectMake(-1, -1, 2, 2);
CAKeyframeAnimation *orbit = [CAKeyframeAnimation animation];
orbit.keyPath = @"position";
orbit.path = CFAutorelease(CGPathCreateWithEllipseInRect(boundingRect, NULL));
orbit.duration = 4;
orbit.additive = YES;
orbit.repeatCount = HUGE_VALF;
orbit.calculationMode = kCAAnimationPaced;
orbit.rotationMode = kCAAnimationRotateAuto;
[b.layer addAnimation:orbit forKey:NULL];
}
- (void)testBase
{
// CABasicAnimation *animation = [CABasicAnimation animation];
// animation.keyPath = @"position.x";
// animation.fromValue = @77;
// animation.toValue = @455;
// animation.duration = 1;
//
// animation.timingFunction = [CAMediaTimingFunction functionWithControlPoints:0.5:0:0.9:0.7];
//
// [b.layer addAnimation:animation forKey:@"basic"];
//
// b.layer.position = CGPointMake(150, 0);
CAKeyframeAnimation* anim = [CAKeyframeAnimation
animationWithKeyPath:@"transform"];
anim.values = [NSArray arrayWithObjects:
[NSValue valueWithCATransform3D:imageView.layer.transform],
[NSValue valueWithCATransform3D:CATransform3DScale
(imageView.layer.transform , 0.1, 0.1, 1)],
[NSValue valueWithCATransform3D:CATransform3DScale
(imageView.layer.transform, 2, 2 , 1)],
[NSValue valueWithCATransform3D:CATransform3DMakeTranslation(0.2, 0.2, 1)],
[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0, 90, 1)],
nil];
anim.duration = 5;
anim.additive = YES;
anim.repeatCount = HUGE_VALF;
anim.rotationMode = kCAAnimationRotateAuto;
anim.calculationMode = kCAAnimationPaced;
anim.removedOnCompletion = NO;
[anim setAutoreverses:YES];
imageView.layer.transform = CATransform3DMakeRotation(M_PI, 0, 90, 1);
[imageView.layer addAnimation:anim forKey:nil];
}
-(void)aaaaa
{
#if 1
//#else
CABasicAnimation *zPosition = [CABasicAnimation animation];
zPosition.keyPath = @"zPosition";
zPosition.fromValue = @-1;
zPosition.toValue = @1;
zPosition.duration = 1.2;
CAKeyframeAnimation *rotation = [CAKeyframeAnimation animation];
rotation.keyPath = @"transform.rotation";
rotation.values = @[ @0, @0.14, @0 ];
rotation.duration = 1.2;
rotation.timingFunctions = @[
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]
];
CAKeyframeAnimation *position = [CAKeyframeAnimation animation];
position.keyPath = @"position";
position.values = @[
[NSValue valueWithCGPoint:CGPointZero],
[NSValue valueWithCGPoint:CGPointMake(110, -20)],
[NSValue valueWithCGPoint:CGPointZero]
];
position.timingFunctions = @[
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]
];
position.additive = YES;
position.duration = 1.2;
CAAnimationGroup *group = [[CAAnimationGroup alloc] init];
group.animations = @[ zPosition, rotation, position ];
group.duration = 1.2;
group.beginTime = 0;
[b.layer addAnimation:group forKey:@"shuffle"];
// b.layer.zPosition = isfront;
//=====================
CAKeyframeAnimation *rotation2 = [CAKeyframeAnimation animation];
rotation2.keyPath = @"transform.rotation";
rotation2.values = @[ @0, @-0.14, @0 ];
rotation2.duration = 1.2;
rotation2.timingFunctions = @[
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]
];
CAKeyframeAnimation *position2 = [CAKeyframeAnimation animation];
position2.keyPath = @"position";
position2.values = @[
[NSValue valueWithCGPoint:CGPointZero],
[NSValue valueWithCGPoint:CGPointMake(-110, -20)],
[NSValue valueWithCGPoint:CGPointZero]
];
position2.timingFunctions = @[
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]
];
position2.additive = YES;
position2.duration = 1.2;
CAAnimationGroup *group2 = [[CAAnimationGroup alloc] init];
group2.animations = @[ zPosition, rotation2, position2];
group2.duration = 1.2;
group2.beginTime = 0;
// btn.layer.zPosition = -isfront;
UIButton *btn = (UIButton *)[self.view viewWithTag:10];
isfront = -isfront;
if (isfront == -1) {
// [self.view insertSubview:btn aboveSubview:b];
b.layer.zPosition = isfront;
btn.layer.zPosition = -isfront;
}
else
{
b.layer.zPosition = isfront;
btn.layer.zPosition = -isfront;
// [self.view insertSubview:b aboveSubview:btn];
}
[btn.layer addAnimation:group2 forKey:@"shuffleReverse"];
// isfront = -isfront;
#endif
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
core animation demo
最新推荐文章于 2018-01-27 11:06:55 发布