ios常用的几个动画代码
#import "MianViewController.h"
#import <QuartzCore/QuartzCore.h> @interface MianViewController ()
{
UIImageView *shakeFeedbackOverlay;
NSTimer *rotateTimer;
int timeCount;
} @end @implementation MianViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. self.title = @"View翻转"; // shakeFeedbackOverlay.alpha = 0.0;
// shakeFeedbackOverlay.layer.cornerRadius = 10.0; //设置圆角半径 shakeFeedbackOverlay = [[UIImageView alloc]initWithFrame:CGRectMake(, , , )];
shakeFeedbackOverlay.backgroundColor = [UIColor redColor];
[self.view addSubview:shakeFeedbackOverlay]; /**左右摇动**/
/*
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 = 20;
[shakeFeedbackOverlay.layer addAnimation:shake forKey:@"shakeAnimation"];
shakeFeedbackOverlay.alpha = 1.0;
[UIView animateWithDuration:5.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction animations:^{
shakeFeedbackOverlay.alpha = 0.0; //透明度变0则消失
} completion:nil];
*/ /**顺时针旋转**/
/*
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 = 99999;
[shakeFeedbackOverlay.layer addAnimation:shake forKey:@"shakeAnimation"];
shakeFeedbackOverlay.alpha = 1.0;
[UIView animateWithDuration:10.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction animations:^{
shakeFeedbackOverlay.alpha = 0.0;
} completion:nil];
*/ /*
CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
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 = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
animation.rotationMode = @"auto";
[shakeFeedbackOverlay.layer addAnimation:animation forKey:@"position"];
*/ /**组合动画**/
/*
CABasicAnimation *flip = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
flip.toValue = [NSNumber numberWithDouble:-M_PI];
CABasicAnimation *scale= [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scale.toValue = [NSNumber numberWithDouble: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;
[shakeFeedbackOverlay.layer addAnimation:group forKey:@"position"];
*/ /*指定时间内旋转图片*/
timeCount = ; //动画执行100次
[self startRotate]; } //启动定时器旋转光圈 - (void)startRotate
{
rotateTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(rotateGraduation)
userInfo:nil
repeats:YES];
} //关闭定时器
- (void)stopTimer
{
if ([rotateTimer isValid])
{
[rotateTimer invalidate];
rotateTimer = nil;
}
} //旋转动画
- (void)rotateGraduation
{
timeCount--;
if (timeCount == )
{
[self stopTimer];
// doSomeThing //旋转完毕 可以干点别的
timeCount = ;
}
else
{
//计算角度 旋转
static CGFloat radian = * (M_PI * / );
CGAffineTransform transformTmp = shakeFeedbackOverlay.transform;
transformTmp = CGAffineTransformRotate(transformTmp, radian);
shakeFeedbackOverlay.transform = transformTmp; }; }
ios常用的几个动画代码的更多相关文章
- iOS学习笔记-自定义过渡动画
代码地址如下:http://www.demodashi.com/demo/11678.html 这篇笔记翻译自raywenderlick网站的过渡动画的一篇文章,原文用的swift,由于考虑到swif ...
- IOS 制作动画代码和 设置控件透明度
方式1: //animateWithDuration用1秒钟的时间,执行代码 [UIView animateWithDuration:1.0 animations:^{ //存放需要执行的动画代码 s ...
- iOS常用第三方开源框架和优秀开发者博客等
博客收藏iOS开发过程好的开源框架.开源项目.Xcode工具插件.Mac软件.文章等,会不断更新维护,希望对你们有帮助.如果有推荐或者建议,请到此处提交推荐或者联系我. 该文档已提交GitHub,点击 ...
- iOS 常用三方类库整理
iOS 常用三方类库整理 1:基于响应式编程思想的oc 地址:https://github.com/ReactiveCocoa/ReactiveCocoa 2:hud提示框 地址:https://gi ...
- iOS常用技术
1.判断系统 #define UMSYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersi ...
- IOS常用第三方库《转》
UI 动画 网络相关 Model 其他 数据库 缓存处理 PDF 图像浏览及处理 摄像照相视频音频处理 响应式框架 消息相关 版本新API的Demo 代码安全与密码 测试及调试 AppleWatch ...
- iOS常用基础框架
一,简述 1.1,IOS操作系统的层次架构 iOS为应用程序开发提供了许多可使用的框架,并构成IOS操作系统的层次架构,分为四层,从上到下依次为:Cocoa Touch Layer( ...
- iOS常用第三方库大全,史上最全第三方库收集
下拉刷新 EGOTableViewPullRefresh – 最早的下拉刷新控件. SVPullToRefresh – 下拉刷新控件. MJRefresh – 仅需一行代码就可以为UITableVie ...
- iOS开发UI篇—核心动画(UIView封装动画)
iOS开发UI篇—核心动画(UIView封装动画) 一.UIView动画(首尾) 1.简单说明 UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView将为这些改变提供动画 ...
随机推荐
- hdu 5432 Pyramid Split(二分搜索)
Problem Description Xiao Ming is a citizen who's good at playing,he has lot's of gold cones which ha ...
- 某APK中使用了动态注册BroadcastReceiver,Launcher中动态加载此APK出现java.lang.SecurityException异常的解决方法
在某APK中,通过如下方法动态注册了一个BroadcastReceiver,代码参考如下: @Override protected void onAttachedToWindow() { super. ...
- 【算法】插入排序 insertion_sort
准备写个<STL 源代码剖析>的读书笔记,开个专栏.名为<STL 的实现>,将源代码整理一遍.非常喜欢侯捷先生写在封底的八个字:天下大事.必作于细.他在书中写到:"我 ...
- EffectiveC#11--选择foreach循环
1.C#的foreach语句可以为你的任何集合产生最好的迭代代码 不推荐如下写法(?原因未明白 作者意思是阻碍jit边界检测) int len = foo.Length; for ( int inde ...
- 《JavaScript 闯关记》之原型及原型链
原型链是一种机制,指的是 JavaScript 每个对象都有一个内置的 __proto__ 属性指向创建它的构造函数的 prototype(原型)属性.原型链的作用是为了实现对象的继承,要理解原型链, ...
- 上传图片预览,支持IE6
//说明:图片上传预览插件 //上传的时候可以生成固定宽高范围内的等比例缩放图 //参数设置: //width 存放图片固定大小容器的宽 //height 存放图片固定大小容器的高 //imgDiv ...
- size_t和size_type类型
size_t一般用来表示一种计数,比如有多少东西被拷贝等.例如:sizeof操作符的结果类型是size_t,该类型保证能容纳实现所建立的最大对象的字节大小. 它的意义大致是“适于计量内存中可容纳的数据 ...
- Ubuntu14.10下解决chromium浏览器无法安装adobe flash的问题
本文参考了一下资源和博客,在此提出表示感谢: http://my.oschina.net/u/209016/blog/290067 http://ubuntuhandbook.org/index.ph ...
- 创建ListView的基本步骤
参考<疯狂android讲义>第2.5节P94 1.创建一个或者多个ListView <LinearLayout xmlns:android="http://schemas ...
- GitHub项目协作基本步骤
1.查找某个项目,然后Fork 2.打开GitHub For Windows,发现刚才Fork的项目 3.对着项目点击Clone,将之复制至本地 4.使用Eclipse等进行开发,如新增一个文件 5. ...