【iOS开发系列】简单动画效果

Autoreverses

DurationDuration方法设定动画的属 性时,它将再次使用你的动画,而非默认的动画。

Speed

倍的速度播放。 这样的影响就是使持续时间减半。如果你指定的持续时间为一半的 持续时间。

BeginTime

这个属性在组动画中很有用。它根据父动画组的持续时间,指定了开始播放动画的时间。默认的是0.0.组 动画在下个段落中讨论“Animation Grouping”。

TimeOffset

如果一个时间偏移量是被设定,动画不会真正的可见,直到根据父动画组中的执行时间得到的时间都流逝了。

RepeatCount

RepeatDuration

下面这段英文摘自苹果官方文档,说的是fromValue toValue ByValue 怎么使用

/* The interpolation values are used as follows: *//** * Both fromValue and toValue are non-nil. Interpolates between fromValue and toValue. * fromValue and byValue are non-nil. Interpolates between fromValue and (fromValue + byValue). * byValue and toValue are non-nil. Interpolates between (toValue – byValue) and toValue. * fromValue is non-nil. Interpolates between fromValue and the current presentation value of the property. * toValue is non-nil. Interpolates between the current value of keyPath in the target layer’s presentation layer andtoValue. * byValue is non-nil. Interpolates between the current value of keyPath in the target layer’s presentation layer and that value * plus byValue. * All properties are nil. Interpolates between the previous value of keyPath in the target layer’s presentation layer and the * current value of keyPath in the target layer’s presentation layer. */

/*————————————————– * 其他的方法,还是属性等,都是继承而来的。 * 我们可以通过animationWithKeyPath键值对的方式来改变动画。 —————————————————-*//* animationWithKeyPath的值 */transform.scale// 比例转换transform.scale.x// 宽度比例转换transform.scale.y// 高度比例转换transform.rotation.z // 平面图的转换margin// 边缘zPosition// z轴位置backgroundColor // 背景颜色cornerRadius // 圆角borderWidth// 边框宽度bounds// 边界contents// 内容contentsRect // 内容矩形frame// 框架hidden// 隐藏的mask// 面具masksToBounds // 面具界限opacity// 透明度position// 位置shadowColor// 阴影颜色shadowOffset // 阴影偏移shadowOpacity // 阴影不透明shadowRadius // 阴影半径

下面是一些例子:

/** * transform.scale 比例缩放 */CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];animation.duration = 0.5 + (rand() % 10) * 0.05;animation.repeatCount = 1;animation.autoreverses = YES;animation.fromValue = [NSNumber numberWithFloat:.8];animation.toValue = [NSNumber numberWithFloat:1.2];[self.ui_View.layer addAnimation:animation forKey:nil];/** * bounds 边界 */CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"bounds"];animation.duration = 1.f;animation.fromValue = [NSValue valueWithCGRect:CGRectMake(0,0,10,10)];animation.toValue = [NSValue valueWithCGRect:CGRectMake(10,10,200,200)];animation.byValue = [NSValue valueWithCGRect:self. ui_View.bounds];// anim.toValue = (id)[UIColor redColor].CGColor;// anim.fromValue = (id)[UIColor blackColor].CGColor;animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];animation.repeatCount = 1;animation.autoreverses = YES;[ui_View.layer addAnimation:animation forKey:nil];/** * cornerRadius 圆弧半径 */CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];animation.duration = 1.f;animation.fromValue = [NSNumber numberWithFloat:0.f];animation.toValue = [NSNumber numberWithFloat:20.f];animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];animation.repeatCount = CGFLOAT_MAX;animation.autoreverses = YES;[ui_View.layer addAnimation:animation forKey:@"cornerRadius"];/** * contents 内容 */CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"contents"];animation.duration = 1.f;animation.fromValue = (id)[UIImage imageNamed:@"1.jpg"].CGImage;animation.toValue = (id)[UIImage imageNamed:@"2.png"].CGImage;// animation.byValue = (id)[UIImage imageNamed:@"3.png"].CGImage;// animation.toValue = (id)[UIColor redColor].CGColor;// animation.fromValue = (id)[UIColor blackColor].CGColor;animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];animation.repeatCount = CGFLOAT_MAX;animation.autoreverses = YES;[ui_View.layer addAnimation:animation forKey:nil];[ui_View.layer setShadowOffset:CGSizeMake(2,2)];[ui_View.layer setShadowOpacity:1];[ui_View.layer setShadowColor:[UIColor grayColor].CGColor];/** * shadowColor 阴影颜色 */CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"shadowColor"];animation.duration = 1.f;animation.toValue = (id)[UIColor redColor].CGColor;animation.fromValue = (id)[UIColor blackColor].CGColor;animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];animation.repeatCount = CGFLOAT_MAX;animation.autoreverses = YES;[ui_View.layer addAnimation:animation forKey:nil];/** * shadowOffset 阴影偏移 */CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"shadowOffset"];animation.duration = 1.f;animation.fromValue = [NSValue valueWithCGSize:CGSizeMake(0,0)];animation.toValue = [NSValue valueWithCGSize:CGSizeMake(3,3)];animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];animation.repeatCount = CGFLOAT_MAX;animation.autoreverses = YES;[ui_View.layer addAnimation:animation forKey:nil];/** * shadowOpacity 阴影不透明 */CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"];animation.duration = 1.f;animation.fromValue = [NSNumber numberWithFloat:0.5];animation.toValue = [NSNumber numberWithFloat:1];animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];animation.repeatCount = CGFLOAT_MAX;animation.autoreverses = YES;[ui_View.layer addAnimation:animation forKey:nil];/** * shadowRadius 阴影半径 */CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"shadowRadius"];animation.duration = 1.f;animation.fromValue = [NSNumber numberWithFloat:10];animation.toValue = [NSNumber numberWithFloat:5];animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];animation.repeatCount = CGFLOAT_MAX;animation.autoreverses = YES;[ui_View.layer addAnimation:animation forKey:nil];

因为有梦,所以勇敢出发,选择出发,便只顾风雨兼程。

【iOS开发系列】简单动画效果

相关文章:

你感兴趣的文章:

标签云: