动画代码片段


//360度转动动画

-(void)rotate360DegreeWithImageView:(UIView *)view{

    CABasicAnimation *animation = [CABasicAnimation

                                  animationWithKeyPath: @"transform" ];

    

    //围绕Z轴旋转,垂直与屏幕

    animation.fromValue = [NSValue valueWithCATransform3D:

                         

                        CATransform3DMakeRotation(M_PI,0.0, 0.0, 1.0) ];

    

    animation.toValue = [NSValuevalueWithCATransform3D:CATransform3DIdentity];

    animation.duration =0.3;

    //旋转效果累计,先转180度,接着再旋转180度,从而实现360旋转

    animation.cumulative =YES;

    animation.repeatCount =1000;


    [view.layeraddAnimation:animation forKey:nil];


}

//停止转动

-(void)stopAnimate:(UIView *)view

{

    [view.layerremoveAllAnimations];


}





//放大缩小的动画

- (void) shakeToShow:(UIView*)aView{

    CAKeyframeAnimation* animation = [CAKeyframeAnimationanimationWithKeyPath:@"transform"];

    animation.duration =0.5;

    

    NSMutableArray *values = [NSMutableArrayarray];

    [values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(0.1,0.1, 1.0)]];

    [values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(1.05,1.05, 1.0)]];

    [values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(0.95,0.95, 1.0)]];

    [values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(1.0,1.0, 1.0)]];

    animation.values = values;

    [aView.layeraddAnimation:animation forKey:nil];

}

//左右抖动动画

-(void)lockAnimationForView:(UIView*)view

{

   CALayer *layer = [view layer];

   CGPoint point = [layer position];

   CGPoint y = CGPointMake(point.x-3.5, point.y);

   CGPoint x = CGPointMake(point.x+3.5, point.y);

    CABasicAnimation * animation = [CABasicAnimationanimationWithKeyPath:@"position"];

    [animation setTimingFunction:[CAMediaTimingFunction

                                 functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

    [animation setFromValue:[NSValuevalueWithCGPoint:x]];

    [animation setToValue:[NSValuevalueWithCGPoint:y]];

    [animationsetAutoreverses:YES];

    [animationsetDuration:0.08];

    [animationsetRepeatCount:2];

    [layeraddAnimation:animation forKey:nil];

}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

// 视图转动动画
+ ( void )shakeView:( UIView *)view duration :(CGFloat)fDuration
{
     if (view && (fDuration >= 0 .1f ))
     {
         CABasicAnimation* shake = [ CABasicAnimation animationWithKeyPath : @"transform.rotation.z" ];
         //设置抖动幅度
         shake .fromValue = [ NSNumber numberWithFloat :- 0 .3 ];
         shake .toValue = [ NSNumber numberWithFloat :+ 0 .3 ];
         shake .duration = 0 .1f ;
         shake .repeatCount = fDuration/ 4 / 0 .1f ;
         shake .autoreverses = YES ;
         [view .layer addAnimation :shake forKey : @"shakeView" ];
     } else {}
}







CAKeyframeAnimation* anim=[ CAKeyframeAnimation animation ];
         anim .keyPath = @"transform.rotation" ;
         anim .values =@[@(angelToRandian(- 7 )),@(angelToRandian( 7 )),@(angelToRandian(- 7 ))];
         anim .repeatCount = MAXFLOAT ;
         anim .duration = 0 .2 ;
         [ self .imageView .layer addAnimation :anim forKey :nil ];


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值