#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常用的几个动画代码的更多相关文章

  1. iOS学习笔记-自定义过渡动画

    代码地址如下:http://www.demodashi.com/demo/11678.html 这篇笔记翻译自raywenderlick网站的过渡动画的一篇文章,原文用的swift,由于考虑到swif ...

  2. IOS 制作动画代码和 设置控件透明度

    方式1: //animateWithDuration用1秒钟的时间,执行代码 [UIView animateWithDuration:1.0 animations:^{ //存放需要执行的动画代码 s ...

  3. iOS常用第三方开源框架和优秀开发者博客等

    博客收藏iOS开发过程好的开源框架.开源项目.Xcode工具插件.Mac软件.文章等,会不断更新维护,希望对你们有帮助.如果有推荐或者建议,请到此处提交推荐或者联系我. 该文档已提交GitHub,点击 ...

  4. iOS 常用三方类库整理

    iOS 常用三方类库整理 1:基于响应式编程思想的oc 地址:https://github.com/ReactiveCocoa/ReactiveCocoa 2:hud提示框 地址:https://gi ...

  5. iOS常用技术

    1.判断系统 #define UMSYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersi ...

  6. IOS常用第三方库《转》

    UI 动画 网络相关 Model 其他 数据库 缓存处理 PDF 图像浏览及处理 摄像照相视频音频处理 响应式框架 消息相关 版本新API的Demo 代码安全与密码 测试及调试 AppleWatch ...

  7. iOS常用基础框架

    一,简述  1.1,IOS操作系统的层次架构         iOS为应用程序开发提供了许多可使用的框架,并构成IOS操作系统的层次架构,分为四层,从上到下依次为:Cocoa Touch Layer( ...

  8. iOS常用第三方库大全,史上最全第三方库收集

    下拉刷新 EGOTableViewPullRefresh – 最早的下拉刷新控件. SVPullToRefresh – 下拉刷新控件. MJRefresh – 仅需一行代码就可以为UITableVie ...

  9. iOS开发UI篇—核心动画(UIView封装动画)

    iOS开发UI篇—核心动画(UIView封装动画) 一.UIView动画(首尾) 1.简单说明 UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView将为这些改变提供动画 ...

随机推荐

  1. 更改debian的软件源sources.list

    之前debian6这系统是在公司装的.公司有百兆光纤,多线接入,就随便选了个源,也没多大问题.现在回到家里变成了2M的ADSL,很多软件更新不下来. 更改软件源,也就修改/etc/apt/source ...

  2. Codeforces Round #389(div 2)

    A =w= B QvQ C 题意:在一个格子图里给出一个路径 里面有UDLR四种移动方向 问 我在格子路径里面最少选几个点 可以让我沿着格子路径走 其实是在相邻的点与点之间走最短路 分析:贪心+模拟 ...

  3. HDU 4362 Dragon Ball 线段树

    #include <cstdio> #include <cstring> #include <cmath> #include <queue> #incl ...

  4. Linux系统守护进程详解ntsysv 可以关掉那些服务

    acpid, haldaemon, messagebus, klogd,network, syslogd  以上几个服务必须开启!其他的分析如下: 1.NetworkManager,NetworkMa ...

  5. 期望dp-hdu-4336-Card Collector

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意: 有n种卡片,每包中至多有一种卡片,概率分别为p1,p2,...pn,可能有的没有卡 ...

  6. [Regular Expressions] Match the Start and End of a Line

    We can use: ^: match the beginning $: match the end Let's say we have the string like the following: ...

  7. Linux下Ant的安装

    OS:CentOS6.3 ant版本:apache-ant-1.9.2-bin 第1步:下载ant apache-ant-1.9.2-bin.tar.gz 第2步:解压 tar -zxvf apach ...

  8. Eclipse安装Vim——viPlugin插件

    1.下载viPlugin: http://www.viplugin.com/files/viPlugin_2.14.0.zip 2.安装 解压后有两个文件夹: features 和 plugins 把 ...

  9. 《JavaScript 闯关记》之原型及原型链

    原型链是一种机制,指的是 JavaScript 每个对象都有一个内置的 __proto__ 属性指向创建它的构造函数的 prototype(原型)属性.原型链的作用是为了实现对象的继承,要理解原型链, ...

  10. J2EE 中 The function valueOf must be used with a prefix when a default namespace is not specified 错误

    jsp页面中,JSTL El表达式字符串比较常用方法 fn:contains 判断字符串是否包含另外一个字符串 <c:if test="${fn:contains(name, sear ...