CABasiAnimation的变化属性

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

下面是一些例子


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

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

下面是一些应用

几个可以用来实现热门APP应用PATH中menu效果的几个方法

+(CABasicAnimation *)opacityForever_Animation:(float)time //永久闪烁的动画

{

    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"opacity"];

    animation.fromValue=[NSNumber numberWithFloat:1.0];

    animation.toValue=[NSNumber numberWithFloat:0.0];

    animation.autoreverses=YES;

    animation.duration=time;

    animation.repeatCount=FLT_MAX;

    animation.removedOnCompletion=NO;

    animation.fillMode=kCAFillModeForwards;

    return animation;

}

 

+(CABasicAnimation *)opacityTimes_Animation:(float)repeatTimes durTimes:(float)time; //有闪烁次数的动画

{

    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"opacity"];

    animation.fromValue=[NSNumber numberWithFloat:1.0];

    animation.toValue=[NSNumber numberWithFloat:0.4];

    animation.repeatCount=repeatTimes;

    animation.duration=time;

    animation.removedOnCompletion=NO;

    animation.fillMode=kCAFillModeForwards;

    animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

    animation.autoreverses=YES;

    return  animation;

}

 

+(CABasicAnimation *)moveX:(float)time X:(NSNumber *)x //横向移动

{

    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];

    animation.toValue=x;

    animation.duration=time;

    animation.removedOnCompletion=NO;

    animation.fillMode=kCAFillModeForwards;

    return animation;

}

 

+(CABasicAnimation *)moveY:(float)time Y:(NSNumber *)y //纵向移动

{

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

    animation.toValue=y;

    animation.duration=time;

    animation.removedOnCompletion=NO;

    animation.fillMode=kCAFillModeForwards;

    return animation;

}

 

+(CABasicAnimation *)scale:(NSNumber *)Multiple orgin:(NSNumber *)orginMultiple durTimes:(float)time Rep:(float)repeatTimes //缩放

{

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

    animation.fromValue=orginMultiple;

    animation.toValue=Multiple;

    animation.duration=time;

    animation.autoreverses=YES;

    animation.repeatCount=repeatTimes;

    animation.removedOnCompletion=NO;

    animation.fillMode=kCAFillModeForwards;

    return animation;

}

 

+(CAAnimationGroup *)groupAnimation:(NSArray *)animationAry durTimes:(float)time Rep:(float)repeatTimes //组合动画

{

    CAAnimationGroup *animation=[CAAnimationGroup animation];

    animation.animations=animationAry;

    animation.duration=time;

    animation.repeatCount=repeatTimes;

    animation.removedOnCompletion=NO;

    animation.fillMode=kCAFillModeForwards;

    return animation;

}

 

+(CAKeyframeAnimation *)keyframeAniamtion:(CGMutablePathRef)path durTimes:(float)time Rep:(float)repeatTimes //路径动画

{

    CAKeyframeAnimation *animation=[CAKeyframeAnimation animationWithKeyPath:@"position"];

    animation.path=path;

    animation.removedOnCompletion=NO;

    animation.fillMode=kCAFillModeForwards;

    animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

    animation.autoreverses=NO;

    animation.duration=time;

    animation.repeatCount=repeatTimes;

    return animation;

}

 

+(CABasicAnimation *)movepoint:(CGPoint )point //点移动

{

    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.translation"];

    animation.toValue=[NSValue valueWithCGPoint:point];

    animation.removedOnCompletion=NO;

    animation.fillMode=kCAFillModeForwards;

    return animation;

}

 

+(CABasicAnimation *)rotation:(float)dur degree:(float)degree direction:(int)direction repeatCount:(int)repeatCount //旋转

{

    CATransform3D rotationTransform  = CATransform3DMakeRotation(degree, 0, 0,direction);

    CABasicAnimation* animation;

    animation = [CABasicAnimation animationWithKeyPath:@"transform"];

 

animation.toValue= [NSValue valueWithCATransform3D:rotationTransform];

    animation.duration= dur;

animation.autoreverses= NO;

    animation.cumulative= YES;

    animation.removedOnCompletion=NO;

    animation.fillMode=kCAFillModeForwards;

    animation.repeatCount= repeatCount;

animation.delegate= self;

 

return animation;

}

时间: 2024-12-28 11:36:43

CABasiAnimation的变化属性的相关文章

css3中的提供的元素变化属性

通过 CSS3 提供的2d元素转换,我们能够对元素进行移动.缩放.转动.拉长或拉伸. css3中为我们 提供了: translate() rotate() scale() skew() matrix() 些方法来对对象进行位移,旋转,缩放,或者拉伸. 注意:Internet Explorer 10.Firefox 以及 Opera 支持 transform 属性. 1. translate() 方法,元素从其当前位置移动,根据给定的 left(x 坐标) 和 top(y 坐标) 位置参数值移动.

CSS3制作动画的三个属性

CSS3属性中有关于制作动画的三个属性:Transform,Transition,Animation:我们一起学习完了Transform和Transition,让我们对元素实现了一些基本的动画效果,这些我想足以让大家激动了一阵子,今天我们趁着这个热劲继续第三个动画属性Animation的学习,单从Animation字面上的意思,我们就知道是“动画”的意思.但CSS3中的Animation与HTML5中的Canvas绘制动画又不同,Animation只应用在页面上已存在的DOM元素上,而且他跟Fl

Property Animation Part II(属性动画 第二部分)

如何使用ValueAnimator ValueAnimator类通过指定一组整数,浮点数,或色彩值,以及动画的持续时间来定义.获得一个ValueAnimator对象的实例需要调用它的一个工厂方法:ofint(),offloat() ,或者ofobject(),如下所示: ValueAnimator animation = ValueAnimator.ofFloat(0f, 1f); animation.setDuration(1000); animation.start(); 在这段代码中,当s

css属性分类介绍

css属性分类介绍 CSS分类目录 文本/字体/颜色 文本相关 字体相关 颜色相关 背景相关 大小/布局 大小属性 margin 外边距 padding 内边距 border 边框 position 定位 列表/表格 多列属性 可伸缩框属性 列表属性 Grid属性 Table属性 动画属性 Animation 动画属性 Transition 过渡属性 CSS属性分类 文本/字体/颜色/背景 字体类 font-family:指定字体 需要考虑客户端机器上是否装有字体 可以排列多个字体,用逗号分隔,

css3中的变形(transform)、过渡(transtion)、动画(animation)

Transform字面上就是变形,改变的意思.在CSS3中transform主要包括以下几种:旋转rotate.扭曲skew.缩放scale和移动translate以及矩阵变形matrix.下面我们一起来看看CSS3中transform的旋转rotate.扭曲skew.缩放scale和移动translate具体如何实现,老样子,我们就从transform的语法开始吧.是构成transtion和animation的基础. 语法: transform : none | <transform-func

WPF控制动画开始、停止、暂停和恢复

1.闲言 好久也没更新一博客了,自己有点发懒,同时确实这几个月来也有点忙.风机监测软件,项目中,有这样一个小需求:正常风机在旋转的时候,上位机软要做一个风机的图片,让它不停地旋转,一但检测到下面风机停止了,上位机软件界面的风机图片也要跟着停止,并且风机图片的旋转速度最好是能够与真实的速度成比例关系,这样软件才更有逼格一点.就是实现这样一个效果,看下图1,左边是一个状态指示,没有做动画,只是做了一个图片的切换,效果还看得过去吧. 图1 风机旋转动画 2.动画制作 在WPF做动画前,首先超码得有3个

iOS:核心动画之关键帧动画CAKeyframeAnimation

CAKeyframeAnimation——关键帧动画 关键帧动画,也是CAPropertyAnimation的子类,与CABasicAnimation的区别是: –CABasicAnimation只能从一个数值(fromValue)变到另一个数值(toValue),而CAKeyframeAnimation会使用一个NSArray保存这些数值 – 属性说明: –values:上述的NSArray对象.里面的元素称为“关键帧”(keyframe).动画对象会在指定的时间(duration)内,依次显

Size over Lifetime 生命周期粒子大小模块

控制每一颗粒子在其生命周期内的大小变化, 属性图: 最后粒子大小为 startSize* 该项设置的参数. 也就是说这边设置的是倍数

[Material Design] 教你做一个Material风格、动画的按钮

前段时间Android L 发布了,相信看过发布会了解过的朋友都为其中的 “Material Design” 感到由衷的惊艳吧!至少我是的. 在惊艳之余感到由衷的遗憾,因为其必须在 ”Android L“ 上才能使用,MD,郁闷啊. 之后便自己想弄一个点击动画试试,此念头一发不可收拾:干脆一不做二不休,就重写了一个 ”MaterialButton“ 控件出来. 在这里不讨论什么是 :“Material Design” . 在这里将给大家分享一下我自己弄的 “Material Design” 风格