zz CABasicAnimation的使用方法

CABasicAnimation类的使用方式就是基本的关键帧动画。

所谓关键帧动画,就是将Layer的属性作为KeyPath来注册,指定动画的起始帧和结束帧,然后自动计算和实现中间的过渡动画的一种动画方式。

CABasicAnimation的基本使用顺序

1.引用QuartzCore.framework

将"QuartzCore.framework"这个库添加到项目中。并且在需要使用CABaseAnimation类的地方import头文件。

[objc] view plaincopy

  1. #import <QuartzCore/QuartzCore.h>

2.CABaseAnimation的实例化以及关键路径的注册

使用"animationWithKeyPath:"方法进行CABasicAnimation的实例化,并指定Layer的属性作为关键路径来注册。

[objc] view plaincopy

  1. // 指定position属性
  2. CABasicAnimation *animation =
  3. [CABasicAnimation animationWithKeyPath:@"position"];

3.设定动画

设定动画的属性。以下是属性及其对应的说明:

属性 说明
duration 动画时长(秒为单位)(注:此处与原文有出入)
repeatCount 重复次数。永久重复的话设置为HUGE_VALF。
beginTime 指定动画开始时间。从开始指定延迟几秒执行的话,请设置为
「CACurrentMediaTime() + 秒数」的形式。
timingFunction 设定动画的速度变化
autoreverses 动画结束时是否执行逆动画

例:

[objc] view plaincopy

  1. animation.duration = 2.5; // 动画持续时间
  2. animation.repeatCount = 1; // 不重复
  3. animation.beginTime = CACurrentMediaTime() + 2; // 2秒后执行
  4. animation.autoreverses = YES; // 结束后执行逆动画
  5. // 动画先加速后减速
  6. animation.timingFunction =
  7. [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut];

4.设定动画的开始帧和结束帧

设定动画开始和结束帧时的状态。设定的值会变为KeyPath所指定的属性的值。

属性 说明
fromValue 开始值
toValue 终了值(絶対値)
byValue 终了值(相对值)

例:

[objc] view plaincopy

  1. // 指定position属性(移动)
  2. CABasicAnimation *animation =
  3. [CABasicAnimation animationWithKeyPath:@"position"];
  4. ???
  5. // 设定动画起始帧和结束帧
  6. animation.fromValue = [NSValue valueWithCGPoint:CGPointMake(0, 0)]; // 起始点
  7. animation.toValue = [NSValue valueWithCGPoint:CGPointMake(320, 480)]; // 终了点

5.添加动画

为Layer添加设置完成的动画,可以给Key指定任意名字。

[objc] view plaincopy

  1. [myView.layer addAnimation:animation forKey:@"move-layer"];

其他.动画结束后回到初始状态的现象的解决方法

用CABasicAnimation执行动画,在动画结束后会回归动画开始前的状态。想要解决的话,必须设置“removedOnCompletion”和“fillMode”这两个属性。

[objc] view plaincopy

  1. // 动画终了后不返回初始状态
  2. animation.removedOnCompletion = NO;
  3. animation.fillMode = kCAFillModeForwards;

CABasicAnimation的使用示例

实际上CABasicAnimation有很多种使用方法,以下将一一列举。

移动动画

移动动画的代码如下:

[objc] view plaincopy

  1. /* 移动 */
  2. CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
  3. // 动画选项的设定
  4. animation.duration = 2.5; // 持续时间
  5. animation.repeatCount = 1; // 重复次数
  6. // 起始帧和终了帧的设定
  7. animation.fromValue = [NSValue valueWithCGPoint:myView.layer.position]; // 起始帧
  8. animation.toValue = [NSValue valueWithCGPoint:CGPointMake(320, 480)]; // 终了帧
  9. // 添加动画
  10. [myView.layer addAnimation:animation forKey:@"move-layer"];

旋转动画

旋转动画的代码如下:

[objc] view plaincopy

  1. /* 旋转 */
  2. // 对Y轴进行旋转(指定Z轴的话,就和UIView的动画一样绕中心旋转)
  3. CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
  4. // 设定动画选项
  5. animation.duration = 2.5; // 持续时间
  6. animation.repeatCount = 1; // 重复次数
  7. // 设定旋转角度
  8. animation.fromValue = [NSNumber numberWithFloat:0.0]; // 起始角度
  9. animation.toValue = [NSNumber numberWithFloat:22 * M_PI]; // 终止角度
  10. // 添加动画
  11. [myView.layer addAnimation:animation forKey:@"rotate-layer"];

缩放动画

缩放动画的代码如下:

[objc] view plaincopy

  1. /* 放大缩小 */
  2. // 设定为缩放
  3. CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  4. // 动画选项设定
  5. animation.duration = 2.5; // 动画持续时间
  6. animation.repeatCount = 1; // 重复次数
  7. animation.autoreverses = YES; // 动画结束时执行逆动画
  8. // 缩放倍数
  9. animation.fromValue = [NSNumber numberWithFloat:1.0]; // 开始时的倍率
  10. animation.toValue = [NSNumber numberWithFloat:2.0]; // 结束时的倍率
  11. // 添加动画
  12. [myView.layer addAnimation:animation forKey:@"scale-layer"];

组合动画

使用CAAnimationGroup类进行复数动画的组合。代码如下:

[objc] view plaincopy

  1. /* 动画1(在X轴方向移动) */
  2. CABasicAnimation *animation1 =
  3. [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
  4. // 终点设定
  5. animation1.toValue = [NSNumber numberWithFloat:80];; // 終点
  6. /* 动画2(绕Z轴中心旋转) */
  7. CABasicAnimation *animation2 =
  8. [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
  9. // 设定旋转角度
  10. animation2.fromValue = [NSNumber numberWithFloat:0.0]; // 开始时的角度
  11. animation2.toValue = [NSNumber numberWithFloat:44 * M_PI]; // 结束时的角度
  12. /* 动画组 */
  13. CAAnimationGroup *group = [CAAnimationGroup animation];
  14. // 动画选项设定
  15. group.duration = 3.0;
  16. group.repeatCount = 1;
  17. // 添加动画
  18. group.animations = [NSArray arrayWithObjects:animation1, animation2, nil nil];
  19. [myView.layer addAnimation:group forKey:@"move-rotate-layer"];

捕获动画开始时和终了时的事件

博主:设定委托对象,实现委托方法,如下:

[objc] view plaincopy

  1. /* 移动 */
  2. CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
  3. animation.delegate = self; // 指定委托对象
  4. // 设定动画选项
  5. animation.duration = 2.5; // 动画时长
  6. animation.repeatCount = 1; // 重复次数
  7. // 终点设定
  8. animation.toValue = [NSNumber numberWithFloat:100];; // 终点
  9. // 添加动画
  10. [myView.layer addAnimation:animation forKey:@"move-layer"];
  11. ???
  12. /**
  13. * 动画开始时
  14. */
  15. - (void)animationDidStart:(CAAnimation *)theAnimation
  16. {
  17. NSLog(@"begin");
  18. }
  19. /**
  20. * 动画结束时
  21. */
  22. - (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
  23. {
  24. NSLog(@"end");
  25. }

CABasicAnimation使用时候的注意点

CABasicAnimation正在进行动画的时候,点击了Home按钮后再回到app的时候,动画会被清空。

Objective-C的示例程序

使用CABasicAnimation实现关键帧动画的示例程序如下:

[objc] view plaincopy

    1. - (void)viewDidLoad
    2. {
    3. [super viewDidLoad];
    4. // 图像显示
    5. UIImage *image = [UIImage imageNamed:@"image01.png"];
    6. UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
    7. imageView.center = CGPointMake(160, 240);
    8. [self.view addSubview:imageView];
    9. /* 移动 */
    10. CABasicAnimation *animation1 =
    11. [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
    12. // 起止点的设定
    13. animation1.toValue = [NSNumber numberWithFloat:100];; // 終点
    14. /* 旋转 */
    15. CABasicAnimation *animation2 =
    16. [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];
    17. // 绕x轴转3圈
    18. animation2.toValue = [NSNumber numberWithFloat:66 * M_PI]; // 结束时的角度
    19. /* 动画组 */
    20. CAAnimationGroup *group = [CAAnimationGroup animation];
    21. group.delegate = self;
    22. group.duration = 5.0;
    23. group.repeatCount = 1;
    24. // 动画结束后不变回初始状态
    25. group.removedOnCompletion = NO;
    26. group.fillMode = kCAFillModeForwards;
    27. // 添加动画
    28. group.animations = [NSArray arrayWithObjects:animation1, animation2, nil nil];
    29. [imageView.layer addAnimation:group forKey:@"move-rotate-layer"];
    30. }
    31. /**
    32. * 动画开始时
    33. */
    34. - (void)animationDidStart:(CAAnimation *)theAnimation
    35. {
    36. NSLog(@"begin");
    37. }
    38. /**
    39. * 动画结束时
    40. */
    41. - (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
    42. {
    43. NSLog(@"end");
    44. }

CABasicAnimation animationWithKeyPath 一些规定的值

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

复制代码

几个可以用来实现热门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;

}

实现view放大再缩小的效果

- (void)viewDidLoad {

    [super viewDidLoad];

layer=[CALayer layer];

layer.frame=CGRectMake(50, 200, 50, 50);

layer.backgroundColor=[UIColor orangeColor].CGColor;

layer.cornerRadius=8.0f;

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

animation.duration=4.0f;

animation.autoreverses=NO;

animation.repeatCount=1;

animation.toValue=[NSNumber numberWithInt:-10];

animation.fromValue=[NSNumber numberWithInt:200];

animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

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

animationZoomIn.duration=2.0f;

animationZoomIn.autoreverses=NO;

animationZoomIn.repeatCount=1;

animationZoomIn.toValue=[NSNumber numberWithFloat:1.56];

animationZoomIn.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

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

animationZoomOut.beginTime=2.0f;

animationZoomOut.duration=2.0f;

animationZoomOut.autoreverses=NO;

animationZoomOut.repeatCount=1;

animationZoomOut.toValue=[NSNumber numberWithFloat:.01];

animationZoomOut.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];

CAAnimationGroup *group=[CAAnimationGroup animation];

group.duration=4.0f;

group.animations=[NSArray arrayWithObjects: animation, animationZoomIn, animationZoomOut,nil];

group.removedOnCompletion=NO;

group.fillMode=kCAFillModeForwards;

[layer addAnimation:group forKey:nil];

[self.view.layer addSublayer:layer];

//layer.hidden=YES;

}
时间: 2024-08-03 11:32:55

zz CABasicAnimation的使用方法的相关文章

CABasicAnimation

前言 本教程写了这个效果图的demo,同时总结CABasicAnimation的使用方法. 看完gif动画完,看到了什么?平移.旋转.缩放.闪烁.路径动画. 实现平移动画 实现平移动画,我们可以通过transform.translation或者水平transform.translation.x或者垂直平移transform.translation.y添加动画. 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

CABasicAnimation精讲

前言 本教程写了这个效果图的demo,同时总结CABasicAnimation的使用方法. 看完gif动画完,看到了什么?平移.旋转.缩放.闪烁.路径动画. 实现平移动画 实现平移动画,我们可以通过transform.translation或者水平transform.translation.x或者垂直平移transform.translation.y添加动画. 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

c调用java

public class MainActivity extends AppCompatActivity { private JNI jni; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); jni = new JNI(); } public void test1(Vie

动画基础--基于Core Animation(3)

参考:https://zsisme.gitbooks.io/ios-/content/ 前面的文章动画基础--基于Core Animation(1),动画基础--基于Core Animation(2)提到了图层的基本概念以及可动画参数几何学等知识. 本片文章将继续探讨更加深入的动画知识. 前面已经两篇文章已经就图层的概念和几何学和效果表现,变换等左列介绍. 在前面的两篇文章中大部分采用了视图自带的backing 图层进行讲解,本身这个图层是禁止动画效果的.所以在前面的文章中很少看到明显的 动画,

Python 面向对象【1】

对象 = 属性 + 方法 面向对象特征:分装 继承 多态[不同对象对同一方法响应不同行动] 类定义 class xxx: .... .... 类对象 类对象支持两种操作:属性引用和实例化 属性引用 使用和 Python 中所有的属性引用一样的标准语法:类对象名.属性名 类对象创建后,类命名空间中所有的命名都是有效属性名.所以如果类定义是这样: class MyClass: i = 12345 def f(self): return 'hello world'  # 实例化类 x = MyClas

没为类型 Node 定义方法 getTextContent (zz)

没有为类型 Node 定义方法 getTextContent (zz) 晚上下班的时候,把班上写了半截的代码带了回来.结果回到家后出乎意料的是回来的时候将代码导入eclipse后,下面这行代码就直接报错了,显示 getTextContent()未定义 . ((Element) ele.getElementsByTagName( "err_code").item(0 )).getTextContent(); 首先想到的是jdk 的版本问题,不可能啊,我昨天才装的jdk 1.6.0_24

Ubuntu下deb包的安装方法 (zz)

Ubuntu下deb包的安装方法 分类: Ubuntu10使用技巧 2010-10-11 23:49 42969人阅读 评论(3) 收藏 举报 ubuntudebdebianlinux deb是debian linus的安装格式,跟red hat的rpm非常相似,最基本的安装命令是:dpkg -i file.deb dpkg 是Debian Package的简写,是为Debian 专门开发的套件管理系统,方便软件的安装.更新及移除.所有源自Debian的Linux发行版都使用dpkg,例如Ubu

CABasicAnimation的基本使用方法(移动&#183;旋转&#183;放大&#183;缩小)

最近iOS开发中用到CoreAnimation的framework来做动画效果,虽然以前也用过,但一直没有系统学习过,今天看到一篇非常详细的博文(虽然是日语,但真的写的很好),在此翻译出来供大家学习. CABasicAnimation类的使用方式就是基本的关键帧动画. 所谓关键帧动画,就是将Layer的属性作为KeyPath来注册,指定动画的起始帧和结束帧,然后自动计算和实现中间的过渡动画的一种动画方式. CABasicAnimation的基本使用顺序 1.引用QuartzCore.framew

托管和非托管转换新方法:Marshaling Library(zz) 【转】

托管和非托管转换新方法:Marshaling Library(zz) 托管和非托管转换新方法:Marshaling Library(zz) http://hi.baidu.com/superql/blog/item/38e9c8073202fcc37a8947ac.html 1.VC++2008中新增加的库:Marshaling Library 我们一起讨论一下VC++2008中引入的新库——Marshaling Library.在这个类库之前我们使用的传统方法是固定指针(pin_ptr).要使