[IOS笔记]

//移动
- (IBAction)translation:(id)sender {
    CABasicAnimation *traslation = [CABasicAnimation animationWithKeyPath:@"position"];
    traslation.toValue = [NSValue valueWithCGPoint:CGPointMake(320,480)];
    traslation.duration = 2.0;
    //traslation.autoreverses = YES;
    traslation.repeatCount = 1;

    [self.m_image.layer addAnimation:traslation forKey:@"traslation"];
}

//透明
- (IBAction)opacity:(id)sender {
    CABasicAnimation *opacity = [CABasicAnimation animationWithKeyPath:@"opacity"];
    opacity.fromValue = [NSNumber numberWithFloat:1.0];
    opacity.toValue = [NSNumber numberWithFloat:0.4];
    opacity.duration = 0.2; //动画时间
    opacity.repeatCount = FLT_MAX; //永久
    opacity.autoreverses = YES; //每次动画后倒回回放
    opacity.removedOnCompletion=NO;  //动画后不还原,为no时不回到最初状态
    opacity.fillMode=kCAFillModeForwards;
    
    [self.m_image.layer addAnimation:opacity forKey:@"opacity"];
}

// 旋转
- (IBAction)rotate:(id)sender {
    CATransform3D ca3d = CATransform3DMakeRotation(45 * 3.14159265/180.0, -1, 1, 1);
    
    CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    rotate.toValue = [NSValue valueWithCATransform3D:ca3d];
    rotate.duration=1.0;
    rotate.autoreverses=NO;
    rotate.repeatCount=1;
    rotate.removedOnCompletion=NO;
    rotate.fillMode=kCAFillModeForwards;
    [self.m_image.layer addAnimation:rotate forKey:@"rotate"];
}

- (IBAction)alpha:(id)sender {
}

//缩放
- (IBAction)scale:(id)sender {
    CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scale.fromValue=[NSNumber numberWithFloat:0.5];
    scale.toValue = [NSNumber numberWithFloat:2.0];
    scale.duration=1.0;
    scale.autoreverses=YES;
    scale.repeatCount=2;
    scale.removedOnCompletion=YES;
    scale.fillMode=kCAFillModeForwards;
    [self.m_image.layer addAnimation:scale forKey:@"scale"];
}

//不按原始边长度缩放
-(IBAction)bounds:(id)sender{
    CABasicAnimation *bounds = [CABasicAnimation animationWithKeyPath:@"bounds"];
    bounds.duration = 1.f;
    bounds.fromValue = [NSValue valueWithCGRect:CGRectMake(0,0,10,10)];
    bounds.toValue = [NSValue valueWithCGRect:CGRectMake(10,10,200,200)];
    bounds.byValue  = [NSValue valueWithCGRect:self. m_image.bounds];

    bounds.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    bounds.repeatCount = 1;
    bounds.autoreverses = YES;
    
    [self.m_image.layer addAnimation:bounds forKey:@"bounds"];
}

- (IBAction)path:(id)sender {
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, nil, 0, 0);
    //添加直线路径
    CGPathAddLineToPoint(path, NULL, 60, 130);
    CGPathAddLineToPoint(path, NULL, 70, 140);
    CGPathAddLineToPoint(path, NULL, 80, 150);
    CGPathAddLineToPoint(path, NULL, 90, 160);
    CGPathAddLineToPoint(path, NULL, 100, 170);
    //添加曲线路径
    CGPathAddCurveToPoint(path,NULL,50.0,275.0,150.0,275.0,70.0,120.0);
    CGPathAddCurveToPoint(path,NULL,150.0,275.0,250.0,275.0,90.0,120.0);
    CGPathAddCurveToPoint(path,NULL,250.0,275.0,350.0,275.0,110.0,120.0);
    CGPathAddCurveToPoint(path,NULL,350.0,275.0,450.0,275.0,130.0,120.0);
    
    animation.path = path;
    animation.duration = 5;
    animation.autoreverses = YES;
    [self.m_image.layer addAnimation:animation forKey:@"path"];
    CFRelease(path);
}
//组合动画
- (IBAction)goup:(id)sender {
    CAAnimationGroup *group = [CAAnimationGroup animation];
    
    CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scale.fromValue=[NSNumber numberWithFloat:0.5];
    scale.toValue = [NSNumber numberWithFloat:2.0];
    
    CABasicAnimation *traslation = [CABasicAnimation animationWithKeyPath:@"position"];
    traslation.toValue = [NSValue valueWithCGPoint:CGPointMake(320,480)];
    
    group.animations=[NSArray arrayWithObjects:scale, traslation, nil];
    group.duration = 2.0;
    
    [self.m_image.layer addAnimation:group forKey:@"group"];
}

参考链接:

http://blog.csdn.net/huifeidexin_1/article/details/8504075

http://www.cnblogs.com/mjios/archive/2013/04/15/3021343.html

原文地址:https://www.cnblogs.com/zengyou/p/3311578.html