iOS常用动画代码
使用前
需引入QuartzCore.framework, 并在相关文件中加入 #import "QuartzCore/QuartzCore.h"
定义
shakeFeedbackOverlay为UIImageView
设置
self.shakeFeedbackOverlay.alpha = 0.0;
self.shakeFeedbackOverlay.layer.cornerRadius = 10.0; //设置圆角半径
、图像左右抖动
CABasicAnimation* shake = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
shake.fromValue = [NSNumber numberWithFloat:-M_PI/];
shake.toValue = [NSNumber numberWithFloat:+M_PI/];
shake.duration = 0.1;
shake.autoreverses = YES; //是否重复
shake.repeatCount = ;
[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:
{
CAKeyframeAnimation *frame=[CAKeyframeAnimation animation];
CGFloat left=-M_PI_2*0.125;
CGFloat right=M_PI_2*0.125;
frame.keyPath=@"postion";
frame.keyPath=@"transform.rotation";
frame.values=@[@(left),@(right),@(left)];
frame.duration = 0.5;
frame.repeatCount = 1000000;
[cell.layer addAnimation:frame forKey:nil];
}
、图像顺时针旋转
CABasicAnimation* shake = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
shake.fromValue = [NSNumber numberWithFloat:];
shake.toValue = [NSNumber numberWithFloat:*M_PI];
shake.duration = 0.8; shake.autoreverses = NO;
shake.repeatCount = ;
[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];
、图像关键帧动画
CAKeyframeAnimation *animation = [CAKeyframeAnimationanimation];
CGMutablePathRef aPath = CGPathCreateMutable();
CGPathMoveToPoint(aPath, nil, , );
CGPathAddCurveToPoint(aPath, nil, , , , , , );
animation.path = aPath;
animation.autoreverses = YES;
animation.duration = ;
animation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseOut];
animation.rotationMode = @"auto";
[ballView.layer addAnimation:animation forKey:@"position"];
、组合动画 CAAnimationGroup
CABasicAnimation *flip = [CABasicAnimationanimationWithKeyPath:@"transform.rotation.y"];
flip.toValue = [NSNumbernumberWithDouble:-M_PI];
CABasicAnimation *scale= [CABasicAnimationanimationWithKeyPath:@"transform.scale"];
scale.toValue = [NSNumbernumberWithDouble:];
scale.duration = 1.5;
scale.autoreverses = YES;
CAAnimationGroup *group = [CAAnimationGroupanimation];
group.animations = [NSArrayarrayWithObjects:flip, scale, nil];
group.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
group.duration = ;
group.fillMode = kCAFillModeForwards;
group.removedOnCompletion = NO;
[ballView.layer addAnimation:group forKey:@"position"];
、指定时间内旋转图片
//启动定时器 旋转光圈
- (void)startRotate
{
self.rotateTimer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(rotateGraduation) userInfo:nil repeats:YES];
}
//关闭定时器
- (void)stopTimer
{
if ([self.rotateTimer isValid])
{
[self.rotateTimer invalidate]; self.rotateTimer = nil;
}
}
//旋转动画
- (void)rotateGraduation
{
self.timeCount--;
if (self.timeCount == )
{
[self stopTimer];
// doSomeThing //旋转完毕 可以干点别的
self.timeCount = ;
}
else
{
//计算角度 旋转
static CGFloat radian = * (M_2_PI / );
CGAffineTransform transformTmp = self.lightImageView.transform;
transformTmp = CGAffineTransformRotate(transformTmp, radian);
self.lightImageView.transform = transformTmp;
};
}
调用方法
self.timeCount = ; //动画执行25次
[self startRotate];
转载自:http://www.cnblogs.com/sell/archive/2013/02/01/2889013.html
iOS常用动画代码的更多相关文章
- IOS 制作动画代码和 设置控件透明度
方式1: //animateWithDuration用1秒钟的时间,执行代码 [UIView animateWithDuration:1.0 animations:^{ //存放需要执行的动画代码 s ...
- ios常用动画
// // CoreAnimationEffect.h // CoreAnimationEffect // // Created by VincentXue on 13-1-19. // Copyri ...
- 【转】IOS 30多个iOS常用动画,带详细注释
原文: http://blog.csdn.net/zhibudefeng/article/details/8691567 CoreAnimationEffect.h 文件 // CoreAnimati ...
- iOS常用动画-b
CoreAnimationEffect.h // CoreAnimationEffect // // Created by VincentXue on 13-1-19. // Copyright ...
- 30多种iOS常用动画
转自:http://blog.csdn.net/zhibudefeng/article/details/8691567 // // CoreAnimationEffect.h // CoreAni ...
- iOS常用动画 类封装
//这是一个很好的动画封装类 很容易明白很详细 和大家分享 // CoreAnimationEffect.h // CoreAnimationEffect // // Created by Vince ...
- iOS 常用开源代码整理
本文章不定期整理. 1.AFNetworking AFNetworking 采用 NSURLConnection + NSOperation, 主要方便与服务端 API 进行数据交换, 操作简单, 功 ...
- iOS常用的代码块整理
strong @property (nonatomic,strong) <#Class#> *<#object#>; weak @property (nonatomic,wea ...
- IOS 常用功能代码
1. 关闭/隐藏键盘 resignFirstResponder 响应view的方法 -(IBAction)fname:(id)sender{ [sender resignFirstResponder] ...
随机推荐
- js基础学习第一天(关于DOM和BOM)一
关于BOM和DOM BOM 下面一幅图很好的说明了BOM和DOM的关系 BOM提供了一些访问窗口对象的一些方法,我们可以用它来移动窗口位置,改变窗口大小,打开新窗口和关闭窗口,弹出对话框,进行导航以及 ...
- ASP.NET缓存策略经验谈
要提升ASP.NET应用程序的性能,最简单.最有效的方式就是使用内建的缓存引擎.虽然也能构建自己的缓存,但由于缓存引擎已提供了如此多的功能,所以完全不必如此麻烦.在很大程度上,ASP.NET开发者在W ...
- Oracle EM 不能访问
zwt2001267 原文 Oracle EM 不能访问 1. cmd控制启动EM: C:\Users\Administrator>emctl start dbconsoleEnvironmen ...
- [Tommas] 一种有效的测试策略(转)
在最近的一个大型项目中,我们在早期就定下了一个目标:不会在软件中使用大量QA人员专注于手工测试.通过手工测试发现bug极其耗时且成本高昂,这促使团队尝试尽可能的将质量内嵌到产品内部.但这并不意味着手工 ...
- 解决duilib使用zip换肤卡顿的问题:修改duilib并使用资源文件换肤
转载请说明原出处,谢谢~~ 今天在做单子是,客户要求做换肤功能,为此我专门写了一个换肤函数,并且把各种皮肤资源压缩为各个zip文件来换肤.但是客户反映程序运行缓慢,我测试后发现的确明显可以看出慢了不少 ...
- 微信web调试工具
做微信公众号开发的时候,最头疼的一件事,莫过于bug调试了. 由于有些功能涉及到权限问题,必须在微信公众号内打开,所以对开发人员来说就是遇到了一场噩梦. 这里有两种方法: 1.工具:mac.使用微信m ...
- 去除下载电影和电视剧文件名中的多余字符[python实现]
讨厌下载电影和电视剧文件名中的多余字符(如网址和广告字样),,搞得文件名好长,可以使用下面的Python代码,自行修改即可. #!\usr\bin\env python # -*- coding: u ...
- reverse the string word by word
题目:Given an input string, reverse the string word by word. For example,Given s = "the sky is bl ...
- mahout 安装
1. 下载mahout-distribution-0.5.tar.gz 并解压: 2.配置环境变量: /etc/profile export MAHOUT_HOME=/home/mahout/ exp ...
- <Chapter 2>2-2-2-1.介绍JSPs,JSTL,和EL(Introducing JSPs, JSTL, and EL)
现在,我们的时钟显示了UTC时区的时间.我们希望我们的应用可以让用户自定义时区,并且为将来的访问记住用户的偏好.为了做到这一点,我们使用Google帐户来识别哪个用户正在使用这个应用. 在我们深入了解 ...