动画,组合动画。

1.     设置位置

      然后

 [UIView animateWithDuration:0.5 animations:^{

            [self.view layoutIfNeeded]; // 写了这个才会执行动画

        }];

 

2.  转圆 加载中 动画

  CABasicAnimation* rotationAnimation;

    rotationAnimation               = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

    rotationAnimation.toValue       = [NSNumber numberWithFloat: M_PI * 2.0 ];

    rotationAnimation.duration      = 1;

    rotationAnimation.cumulative    = YES;

    rotationAnimation.repeatCount   = MAXFLOAT;

    

    [self.circleImgV.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];

 

3.  

 

  [CATransaction begin];

    [CATransaction begin];

    [CATransaction setAnimationDuration:2];

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

    [CATransaction commit];

    [CATransaction setAnimationDuration:2];

    myLayer.backgroundColor = [UIColor blueColor].CGColor;

    [CATransaction commit];

3.  /*****高级动画*****/

 

-(void)transition

{

/*

    CATransition *atr = [CATransition animation];

    atr.type = @"rippleEffect";

    atr.duration = 2;

//设置为YES  会使得动画的视图返回到初始值

    atr.autoreverses = YES;

    [myLayer addAnimation:atr forKey:@"ripple"];

*/

 

//关键帧动画

    /*

    CAKeyframeAnimation *anmation = [CAKeyframeAnimation animationWithKeyPath:@"backgroundColor"];

    anmation.values = @[(id)[UIColor redColor].CGColor,(id)[UIColor yellowColor].CGColor,(id)[UIColor blueColor].CGColor,(id)[UIColor  greenColor].CGColor];

    anmation.duration = 2;

    //设置为YES  会使得动画的视图返回到初始值

    anmation.autoreverses = YES;

    [myLayer addAnimation:anmation forKey:@"backGroudColor"];

*/

 

    //组合动画

    CABasicAnimation *anmiation = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];

    anmiation.duration = 5;

    anmiation.autoreverses = YES;

    anmiation.fromValue = (id)myLayer.backgroundColor;

    anmiation.toValue = (id)[UIColor redColor].CGColor;

 

    CABasicAnimation *anmiationTwo = [CABasicAnimation  animationWithKeyPath:@"position"];

    anmiationTwo.duration = 2;

    anmiationTwo.autoreverses = YES;

 

    anmiationTwo.fromValue = [NSValue valueWithCGPoint:myLayer.position];

   CGPoint point = myLayer.position;

    point.y += 100;

    anmiationTwo.toValue = [NSValue valueWithCGPoint:point];

 

    CAAnimationGroup *group = [CAAnimationGroup animation];

    group.duration = 5;

    group.autoreverses = YES;

    group.animations = @[anmiation,anmiationTwo];

    [myLayer addAnimation:group forKey:nil];

}

posted @ 2016-08-08 15:06  阳光普照大地  阅读(194)  评论(0编辑  收藏  举报