iOS中几个动画代码

//需要引入QuartzCore.framework,并在相关文件中加入#import <QuartzCore/QuartzCore.h>

Self.imageView.alpha = 0.0;

Self.imageView.layer.cornerRadius = 10.0;     //设置圆角半径

 

 

1、图像左右抖动

   CABasicAnimation* shake = [CABasicAnimationanimationWithKeyPath:@"transform.rotation.z"];

   shake.fromValue = [NSNumber numberWithFloat:-M_PI/32];

   shake.toValue = [NSNumber numberWithFloat:+M_PI/32];

   shake.duration = 0.1;

   shake.autoreverses = YES; //是否重复

   shake.repeatCount = 4;

   [self.shakeFeedbackOverlay.layer addAnimation:shakeforKey:@"shakeAnimation"];

   self.shakeFeedbackOverlay.alpha = 1.0;

   [UIView animateWithDuration:2.0 delay:0.0options:UIViewAnimationOptionCurveEaseIn |UIViewAnimationOptionAllowUserInteraction animations:^{self.shakeFeedbackOverlay.alpha = 0.0; //透明度变0则消失 }completion:nil];

2、图像顺时针旋转

   CABasicAnimation* shake = [CABasicAnimationanimationWithKeyPath:@"transform.rotation.z"];

   shake.fromValue = [NSNumber numberWithFloat:0];

   shake.toValue = [NSNumber numberWithFloat:2*M_PI];

   shake.duration = 0.8; shake.autoreverses = NO;

   shake.repeatCount = 1;

   [self.shakeFeedbackOverlay.layer addAnimation:shakeforKey:@"shakeAnimation"];

   self.shakeFeedbackOverlay.alpha = 1.0;

   [UIView animateWithDuration:10.0 delay:0.0options:UIViewAnimationOptionCurveEaseIn |UIViewAnimationOptionAllowUserInteraction animations:^{self.shakeFeedbackOverlay.alpha = 0.0; } completion:nil];

3、图像关键帧动画 

   CAKeyframeAnimation*animation = [CAKeyframeAnimationanimation];

   CGMutablePathRef aPath= CGPathCreateMutable();

   CGPathMoveToPoint(aPath, nil, 20,20);

   CGPathAddCurveToPoint(aPath, nil, 160,30, 220, 220, 240, 420);

   animation.path = aPath;

   animation.autoreverses = YES;

   animation.duration = 2;

   animation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseOut];

   animation.rotationMode = @"auto";

   [ballView.layer addAnimation:animationforKey:@"position"];

4、组合动画 CAAnimationGroup 

   CABasicAnimation *flip= [CABasicAnimationanimationWithKeyPath:@"transform.rotation.y"];

   flip.toValue = [NSNumbernumberWithDouble:-M_PI];

   

   CABasicAnimation*scale= [CABasicAnimationanimationWithKeyPath:@"transform.scale"];

   scale.toValue = [NSNumbernumberWithDouble:12];

   scale.duration = 1.5;

   scale.autoreverses = YES;

   

   CAAnimationGroup*group = [CAAnimationGroupanimation];

   group.animations = [NSArrayarrayWithObjects:flip, scale, nil];

   group.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];

   group.duration = 3;

   group.fillMode = kCAFillModeForwards;

   group.removedOnCompletion = NO;

   [ballView.layer addAnimation:groupforKey:@"position"];

5、指定时间内旋转图片

//启动定时器旋转光圈

- (void)startRotate

{

   self.rotateTimer = [NSTimerscheduledTimerWithTimeInterval:0.02

                                               target:self

                                             selector:@selector(rotateGraduation)

                                             userInfo:nil

                                              repeats:YES];

}

//关闭定时器

- (void)stopTimer

{

   if ([self.rotateTimerisValid])

{

       [self.rotateTimerinvalidate];

       self.rotateTimer = nil;

   }

}

 

//旋转动画

- (void)rotateGraduation

{

   self.timeCount--;

   if (self.timeCount == 0)

   {

       [self stopTimer];

       // doSomeThing //旋转完毕 可以干点别的

       self.timeCount = 25;

   }

   else

   {

       //计算角度 旋转

       static CGFloatradian = 150 * (M_2_PI / 360);

       CGAffineTransformtransformTmp = self.lightImageView.transform;

       transformTmp = CGAffineTransformRotate(transformTmp,radian);

       self.lightImageView.transform =transformTmp;

   };

}

调用方法

self.timeCount= 25; //动画执行25次

[self startRotate]; 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值