使用前

        需引入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常用动画代码的更多相关文章

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

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

  2. ios常用动画

    // // CoreAnimationEffect.h // CoreAnimationEffect // // Created by VincentXue on 13-1-19. // Copyri ...

  3. 【转】IOS 30多个iOS常用动画,带详细注释

    原文: http://blog.csdn.net/zhibudefeng/article/details/8691567 CoreAnimationEffect.h 文件 // CoreAnimati ...

  4. iOS常用动画-b

    CoreAnimationEffect.h //  CoreAnimationEffect // //  Created by VincentXue on 13-1-19. //  Copyright ...

  5. 30多种iOS常用动画

    转自:http://blog.csdn.net/zhibudefeng/article/details/8691567 // //  CoreAnimationEffect.h //  CoreAni ...

  6. iOS常用动画 类封装

    //这是一个很好的动画封装类 很容易明白很详细 和大家分享 // CoreAnimationEffect.h // CoreAnimationEffect // // Created by Vince ...

  7. iOS 常用开源代码整理

    本文章不定期整理. 1.AFNetworking AFNetworking 采用 NSURLConnection + NSOperation, 主要方便与服务端 API 进行数据交换, 操作简单, 功 ...

  8. iOS常用的代码块整理

    strong @property (nonatomic,strong) <#Class#> *<#object#>; weak @property (nonatomic,wea ...

  9. IOS 常用功能代码

    1. 关闭/隐藏键盘 resignFirstResponder 响应view的方法 -(IBAction)fname:(id)sender{ [sender resignFirstResponder] ...

随机推荐

  1. FFMPEG + SDL音频播放分析

    目录 [hide] 1 抽象流程: 2 关键实现: 2.1 main()函数 2.2 decode_thread()读取文件信息和音频包 2.3 stream_component_open():设置音 ...

  2. WEXT driver的执行过程实现(iwpriv部分/softapcontroller)

    之前在看wifi driver源代码时一直有一个疑惑就是net dev的wireless_handlers中(WEXT类型的接口)提供两个iw_handler接口,怎么知道上层是调用的是private ...

  3. mybatis返回HashMap结果类型与映射

    <!-- 返回HashMap结果 类型--> <!-- 如果想返回JavaBean,只需将resultType设置为JavaBean的别名或全限定名 --> <!-- T ...

  4. Android selector item 属性大全(按钮按下不同效果)

    <selector>         必须.必须是根元素.包含一个或多个<item>元素.          Attributes:             xmlns:and ...

  5. POJ 3321- Apple Tree(标号+BIT)

    题意: 给你一棵树,初始各节点有一个苹果,给出两种操作,C x 表示若x节点有苹果拿掉,无苹果就长一个. Q x查询以x为根的子树中有多少个苹果. 分析: 开始这个题无从下手,祖先由孩子的标号不能确定 ...

  6. SQL Server缺省约束、列约束和表约束

    SQL Server缺省约束是SQL Server数据库中的一种约束,下面就为您介绍SQL Server缺省约束.列约束和表约束的定义方法啊,供您参考. SQL Server缺省约束 SQL Serv ...

  7. javascript AES加密 C#AES解密实现

    首先需要引入js类库 crypto-js(开源),地址:http://code.google.com/p/crypto-js 现在很多人无法打开这个地址不要紧,下面我们会将全部代码贴出来 需要引入 a ...

  8. 微信公众平台开发 ACCESS TOKEN

    获取access token 返回 access_token是公众号的全局唯一票据,公众号调用各接口时都需使用access_token.正常情况下access_token有效期为7200秒,重复获取将 ...

  9. 卸载 Cloudera Manager 5.1.x.和 相关软件【官网翻译】

    问题导读: 1.不同的安装方式,卸载方法存在什么区别?2.不同的操作系统,卸载 Cloudera Manager Server and 数据库有什么区别? 重新安装不完整如果你来到这里,因为你的安装没 ...

  10. 第二百九十五天 how can i 坚持

    买了个小米电话卡,写的让周六日送,非得今天给送来,浪费了1块钱.买回来还没法激活,这.. 昨天差点挂掉,今天感觉好多了,不过今天好冷,回来快冻死了. 今天啊,年终奖订下来了,没有想象的高 啊,有点小失 ...