1、我们是采用Core
Animatioin创建动画的常,实质上是还改CALayer的性能,然后给这些性流畅的转移。可以动用Core
Animation对象的职、颜色、透明度与CGAffine变换来做动画。

2、一个简的微动画

/隐式动画/

 

  • (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地图