壹 、大家是运用Core
Animatioin创制动画的时,实质上是更改CALayer的习性,然后让那些属性流畅的转变。能够行使Core
Animation对象的岗位、颜色、折射率以及CGAffine变换到制作动画。

贰 、二个简短的小动画

/隐式动画/

 

  • (void)viewDidLoad
    {

    [super viewDidLoad];

    UIImageView
*imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,
40, 40)];

    [UIView beginAnimations:nil context:NULL];

    [UIView setAnimationDuration:2.0];  //设置动画时间长度

    CGAffineTransform
moveTransform = CGAffineTransformMakeTranslation(200, 300);  //移动到稳定的职务

    [imageView.layer
setAffineTransform:moveTransform];

    imageView.layer.opacity = 1;

    

    [UIView commitAnimations];

    imageView.backgroundColor = [UIColor redColor];

    

    [self.view addSubview:imageView];

 

}

/彰显动画/

  • (void)viewDidLoad
    {

    [super viewDidLoad];

    UIImageView
*imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,
40, 40)];

    imageView.backgroundColor = [UIColor redColor];

 

    CABasicAnimation
*opAnim = [CABasicAnimation animationWithKeyPath:@”opacity”];

    opAnim.duration =
3.0;

    //定义早先和甘休的光滑度

    opAnim.fromValue
= [NSNumber numberWithFloat:1.0];

    opAnim.toValue =
[NSNumber numberWithFloat:0];

    opAnim.cumulative
= YES;

    opAnim.repeatCount = 6;    //重复次数

    [imageView.layer
addAnimation:opAnim forKey:@”animateOpacity”];

    CGAffineTransform
moveTransform = CGAffineTransformMakeTranslation(200, 300);

    CABasicAnimation
*moveAnim = [CABasicAnimation animationWithKeyPath:@”transform”];

    moveAnim.duration
= 6.0;

    moveAnim.toValue
= [NSValue valueWithCATransform3D:CATransform3DMakeAffineTransform(moveTransform)];

    [imageView.layer
addAnimation:moveAnim forKey:@”animateTransform”];

    

    [self.view addSubview:imageView];

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图