CABasicAnimation animationWithKeyPath 一些规定的值(Layer层动画)

来源:互联网 发布:成都软件开发 编辑:程序博客网 时间:2024/06/05 09:40
CABasicAnimation animationWithKeyPath Types

When using the ‘CABasicAnimation’ from the QuartzCore Framework in Objective-C, you have to specify an animationWithKeyPath. This is a long string and is not easily listed in the CABasicAnimation, CAPropertyAnimation, or the CAAnimation class. I ended up finding a handy chart within the Core Animation Programming guide in Apple’s iPhone OS Reference Library. Hope this helps save someone time, at least it will for me.

CABasicAnimation *theAnimation;

theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.y"];

theAnimation.delegate = self;

theAnimation.duration = 1;

theAnimation.repeatCount = 0;

theAnimation.removedOnCompletion = FALSE;

theAnimation.fillMode = kCAFillModeForwards;

theAnimation.autoreverses = NO;

theAnimation.fromValue = [NSNumber numberWithFloat:0];

theAnimation.toValue = [NSNumber numberWithFloat:-60];

[self.view.layer addAnimation:theAnimation forKey:@"animateLayer"];





我们可以通过animationWithKeyPath键值对的方式来改变动画

animationWithKeyPath的值:



transform.scale = 比例轉換

transform.scale.x = 闊的比例轉換

transform.scale.y = 高的比例轉換

transform.rotation.z = 平面圖的旋轉

opacity = 透明度



margin

zPosition



backgroundColor



cornerRadius

borderWidth





bounds

contents



contentsRect

cornerRadius

frame



hidden



mask



masksToBounds

opacity



position



shadowColor



shadowOffset



shadowOpacity

shadowRadius

[self. ui_View.layer removeAllAnimations];



CABasicAnimation *pulse = [CABasicAnimation animationWithKeyPath:@"transform.scale"];

pulse.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];

pulse.duration = 0.5 + (rand() % 10) * 0.05;

pulse.repeatCount = 1;

pulse.autoreverses = YES;

pulse.fromValue = [NSNumber numberWithFloat:.8];

pulse.toValue = [NSNumber numberWithFloat:1.2];

[self.ui_View.layer addAnimation:pulse forKey:nil];



// bounds



CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"bounds"];

anim.duration = 1.f;

anim.fromValue = [NSValue valueWithCGRect:CGRectMake(0,0,10,10)];

anim.toValue = [NSValue valueWithCGRect:CGRectMake(10,10,200,200)];

anim.byValue = [NSValue valueWithCGRect:self. ui_View.bounds];

// anim.toValue = (id)[UIColor redColor].CGColor;

// anim.fromValue = (id)[UIColor blackColor].CGColor;



anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

anim.repeatCount = 1;

anim.autoreverses = YES;



[ui_View.layer addAnimation:anim forKey:nil];

//cornerRadius



CABasicAnimation *anim2 = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];

anim2.duration = 1.f;

anim2.fromValue = [NSNumber numberWithFloat:0.f];

anim2.toValue = [NSNumber numberWithFloat:20.f];

anim2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

anim2.repeatCount = CGFLOAT_MAX;

anim2.autoreverses = YES;



[ui_View.layer addAnimation:anim2 forKey:@"cornerRadius"];



//contents



CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"contents"];

anim.duration = 1.f;

anim.fromValue = (id)[UIImage imageNamed:@"1.jpg"].CGImage;

anim.toValue = (id)[UIImage imageNamed:@"2.png"].CGImage;

// anim.byValue = (id)[UIImage imageNamed:@"3.png"].CGImage;

// anim.toValue = (id)[UIColor redColor].CGColor;

// anim.fromValue = (id)[UIColor blackColor].CGColor;



anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

anim.repeatCount = CGFLOAT_MAX;

anim.autoreverses = YES;



[ui_View.layer addAnimation:anim forKey:nil];







[ui_View.layer setShadowOffset:CGSizeMake(2,2)];

[ui_View.layer setShadowOpacity:1];

[ui_View.layer setShadowColor:[UIColor grayColor].CGColor];

//

CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"shadowColor"];

anim.duration = 1.f;

anim.toValue = (id)[UIColor redColor].CGColor;

anim.fromValue = (id)[UIColor blackColor].CGColor;



anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

anim.repeatCount = CGFLOAT_MAX;

anim.autoreverses = YES;



[ui_View.layer addAnimation:anim forKey:nil];



CABasicAnimation *_anim = [CABasicAnimation animationWithKeyPath:@"shadowOffset"];

_anim.duration = 1.f;

_anim.fromValue = [NSValue valueWithCGSize:CGSizeMake(0,0)];

_anim.toValue = [NSValue valueWithCGSize:CGSizeMake(3,3)];



_anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

_anim.repeatCount = CGFLOAT_MAX;

_anim.autoreverses = YES;



[ui_View.layer addAnimation:_anim forKey:nil];





CABasicAnimation *_anim1 = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"];

_anim1.duration = 1.f;

_anim1.fromValue = [NSNumber numberWithFloat:0.5];

_anim1.toValue = [NSNumber numberWithFloat:1];



_anim1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

_anim1.repeatCount = CGFLOAT_MAX;

_anim1.autoreverses = YES;



[ui_View.layer addAnimation:_anim1 forKey:nil];







CABasicAnimation *_anim2 = [CABasicAnimation animationWithKeyPath:@"shadowRadius"];

_anim2.duration = 1.f;

_anim2.fromValue = [NSNumber numberWithFloat:10];

_anim2.toValue = [NSNumber numberWithFloat:5];



_anim2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

_anim2.repeatCount = CGFLOAT_MAX;

_anim2.autoreverses = YES;



[ui_View.layer addAnimation:_anim2 forKey:nil];


转自:http://blog.sina.com.cn/s/blog_65a8ab5d01019eve.html

原创粉丝点击