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] ...
随机推荐
- 批量添加-fno-objc-arc
http://syxiaqj.github.io/2014/02/28/bee-learning-1/ 4.批量添加-fno-objc-arc 因为BeeFramework是一个非RAC的框架,现在X ...
- Blog CSS
你好 print("你好.") haode
- 用Apache Kafka构建流数据平台的建议
在<流数据平台构建实战指南>第一部分中,Confluent联合创始人Jay Kreps介绍了如何构建一个公司范围的实时流数据中心.InfoQ前期对此进行过报道.本文是根据第二部分整理而成. ...
- 转载:看c++ primer 学习心得
学习C++ Primer时遇到的问题及解释 chenm91 感觉: l 啰嗦有时会掩盖主题:这本书确实有些啰嗦,比如在讲函数重载的时候,讲了太长一大段(有两节是打了*号的,看还是不看 ...
- codeforces 260 div2 B题
打表发现规律,对4取模为0的结果为4,否则为0,因此只需要判断输入的数据是不是被4整出即可,数据最大可能是100000位的整数,判断能否被4整出不能直接去判断,只需要判断最后两位(如果有)或一位能否被 ...
- 【LR】版本问题
前台信息工作笔记本系统是: widows7 64位操作系统 (1)loadrunner11 软件 --兼容性问题的解决与环境配置要求 地址:http://bgwan.blog.163.com/blog ...
- String.Format格式说明
原文地址:http://www.cnblogs.com/tuyile006/archive/2006/07/13/449884.aspx C#格式化数值结果表 字符 说明 示例 输出 C 货币 str ...
- C++ 使用Htmlcxx解析Html内容(VS编译库文件)
1.下载Htmlcxx,http://sourceforge.net/projects/htmlcxx/ 2.解压htmlcxx-0.85.tar.gz 3.打开htmlcxx.vcproj,注意是h ...
- bookhub -- 扁平化本地电子书管理与分享工具
代码 github 地址:https://github.com/JackonYang/bookhub 初稿: 1. 关键功能点 扫描本地电子书(扩展名 pdf/epub 等),将不重复的复制到特 ...
- wireshark http过程
一直研究lighttpd源码,顺便看下网络编程,不说太多,开始吧 第一步 设置wireshark过滤规则 tcp.port eq 81 ,然后开始捕捉 第二步 http://183.61.16.16 ...