您的位置:首页 > 其它

自定义动画--角度抖动、路径旋转、左右晃动

2016-07-12 15:43 260 查看
 

 self.label1 = [[UILabelalloc]initWithFrame:CGRectMake(50,50,50,50)];

    self.label1.backgroundColor = [UIColorredColor];

    self.label1.text =@"旋转路径";

    [self.viewaddSubview:self.label1];

//图标抖动动画

CAKeyframeAnimation * keyAnimaion = [CAKeyframeAnimationanimation];

    keyAnimaion.keyPath =@"transform.rotation";

    keyAnimaion.values =@[@(-10 /180.0 *
M_PI),@(10 /180.0 *M_PI),@(-10/180.0
* M_PI),@(0)];//度数转弧度

    

    keyAnimaion.removedOnCompletion =NO;

    keyAnimaion.fillMode =kCAFillModeForwards;

    keyAnimaion.duration =0.2;

    keyAnimaion.repeatCount =MAXFLOAT;

    [self.label1.layeraddAnimation:keyAnimaion
forKey:nil];

//******************************//

//路径加旋转动画组合

//添加路径

    CGMutablePathRef path = CGPathCreateMutable();

    CGPathMoveToPoint(path, nil, 0, 0);

    CGPathAddCurveToPoint(path, nil, 0, 0, 200, 100, 0, 400);

    

    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];

    animation.path = path;

    animation.removedOnCompletion = NO;

    animation.fillMode = kCAFillModeForwards ;

    animation.timingFunction = [CAMediaTimingFunction functionWithName : kCAMediaTimingFunctionEaseIn];

    animation.autoreverses = NO ;

    animation.duration = 1;

    animation.repeatCount = MAXFLOAT;

    

    //添加旋转

    CATransform3D rotationTransform = CATransform3DMakeRotation(M_PI, 50 , 100 , 0);

    CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"transform"];

    

    animation1.toValue = [ NSValue valueWithCATransform3D :rotationTransform];

    animation1.duration =  0.1;

    animation1.autoreverses = YES ;

    animation1.cumulative = NO ;

    animation1.fillMode = kCAFillModeForwards ;

    animation1.repeatCount = MAX_INPUT;

    

    [self.label1.layer addAnimation:animation forKey:@"旋转路径"];

    [self.label1.layer addAnimation:animation1 forKey:nil];

/***********************************/

//左右晃动动画

  CAKeyframeAnimation * animation = [CAKeyframeAnimation
animationWithKeyPath:@"transform.translation.x"];

    CGFloat currentTx =
self.label1.transform.ty;

    NSLog(@"%f",currentTx);

//  animation.delegate = self;

    animation.duration =
0.5;

    animation.values =
@[ @(currentTx),
@(currentTx + 10),
@(currentTx-8),
@(currentTx + 8),
@(currentTx -5),
@(currentTx + 5),
@(currentTx)
];

    animation.repeatCount =
5;

    //时间段

    //animation.keyTimes = @[ @(0), @(0.225), @(0.425), @(0.6), @(0.75), @(0.875), @(1) ];

    //动画出现先快后慢

   //animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    [self.label1.layer
addAnimation:animation forKey:nil];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: