iOS常用的几个动画代码

iOS常用的几个动画代码,第1张

概述iOS常用的几个动画代码

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

使用前        需引入QuartzCore.framework,并在相关文件中加入 #import "QuartzCore/QuartzCore.h"定义         shakeFeedbackOverlay为UIImageVIEw设置         self.shakeFeedbackOverlay.Alpha = 0.0;         self.shakeFeedbackOverlay.layer.cornerRadius = 10.0; //设置圆角半径1、图像左右抖动    CABasicAnimation* shake = [CABasicAnimation animationWithKeyPath:@"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:shake forKey:@"shakeAnimation"];    self.shakeFeedbackOverlay.Alpha = 1.0;    [UIVIEw animateWithDuration:2.0 delay:0.0 options:UIVIEwAnimationoptionCurveEaseIn | UIVIEwAnimationoptionAllowUserInteraction animations:^{ self.shakeFeedbackOverlay.Alpha = 0.0; //透明度变0则消失 } completion:nil];2、图像顺时针旋转    CABasicAnimation* shake = [CABasicAnimation animationWithKeyPath:@"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:shake forKey:@"shakeAnimation"];    self.shakeFeedbackOverlay.Alpha = 1.0;    [UIVIEw animateWithDuration:10.0 delay:0.0 options:UIVIEwAnimationoptionCurveEaseIn | UIVIEwAnimationoptionAllowUserInteraction animations:^{ self.shakeFeedbackOverlay.Alpha = 0.0; } completion:nil];3、图像关键帧动画     CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];    CGMutablePathref aPath = CGPathCreateMutable();    CGPathMovetoPoint(aPath,nil,20,20);    CGPathAddCurvetoPoint(aPath,160,30,220,240,420);    animation.path = aPath;    animation.autoreverses = YES;    animation.duration = 2;    animation.timingFunction = [camediatimingFunction functionWithname:kcamediatimingFunctionEaSEOut];    animation.rotationMode = @"auto";    [ballVIEw.layer addAnimation:animation forKey:@"position"];4、组合动画 CAAnimationGroup    CABasicAnimation *flip = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];    flip.tovalue = [NSNumbernumberWithDouble:-M_PI];    CABasicAnimation *scale= [CABasicAnimation animationWithKeyPath:@"transform.scale"];    scale.tovalue = [NSNumbernumberWithDouble:12];    scale.duration = 1.5;    scale.autoreverses = YES;    CAAnimationGroup *group = [CAAnimationGroup animation];    group.animations = [NSArray arrayWithObjects:flip,scale,nil];    group.timingFunction = [camediatimingFunction functionWithname:kcamediatimingFunctionEaseInEaSEOut];    group.duration = 3;    group.fillMode = kCAFillModeForwards;    group.removedOnCompletion = NO;    [ballVIEw.layer addAnimation:group forKey:@"position"];5、指定时间内旋转图片//启动定时器旋转光圈- (voID)startRotate{    self.rotateTimer = [NSTimer scheduledTimerWithTimeInterval: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 CGfloat radian = 150 * (M_2_PI / 360);        CGAffinetransform transformTmp = self.lightimageVIEw.transform;        transformTmp = CGAffinetransformRotate(transformTmp,radian);        self.lightimageVIEw.transform = transformTmp;    };}调用方法self.timeCount = 25; //动画执行25次[self startRotate];

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的iOS常用的几个动画代码全部内容,希望文章能够帮你解决iOS常用的几个动画代码所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1107772.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存