使用前

        需引入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. Android 版本自动更新

    截图如下: 代码实现如下: package com.update.apk; import java.io.BufferedReader; import java.io.File; import jav ...

  2. JAVA数据库处理(连接,数据查询,结果集返回)

    package john import java.io.IOException; import java.util.*; public class QueryDataRow { public Hash ...

  3. java web 学习八(HttpServletResponse对象2)

    一.HttpServletResponse常见应用——生成验证码 1.1.生成随机图片用作验证码 生成图片主要用到了一个BufferedImage类,

  4. Jacoco远程统计代码覆盖率

    Jacoco   什么是Jacoco? Jacoco是一个开源的Java代码覆盖率工具,Jacoco可以嵌入到Ant .Maven中,并提供了EclEmma Eclipse插件,也可以使用JavaAg ...

  5. HTML 表单提交 的简单代码

    <form action="check.php" method="post"> 用户名:<input type="text" ...

  6. uC/OS - III 移植 IAR平台

    关于移植uC/OS-III 网上已经有很多教程了此处只是做个记录 首先下载源码然后解压得到下面的文件: 然后在模版工程里新建各种文件夹: 最后全部都添加进工程: OK了,编译一下,惊呆了,竟然 0错误 ...

  7. 常用的CSS Hack技术集锦

    来源:http://www.ido321.com/938.html 一.什么是CSS Hack? 不同的浏览器对CSS的解析结果是不同的,因此会导致相同的CSS输出的页面效果不同,这就需要CSS Ha ...

  8. mybatis系列-08-动态sql

    8.1     什么是动态sql mybatis核心 对sql语句进行灵活操作,通过表达式进行判断,对sql进行灵活拼接.组装. 8.2     需求 用户信息综合查询列表和用户信息查询列表总数这两个 ...

  9. Tip提示框另类写法

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. jsp文件上传、下载

    一.文件上传 上传文件是Web开发中经常要用到的功能:例如在基于B/S的人事信息管理系统中上传照片,在新闻发布系统中上传图片等等.....要实现文件上传功能,就需要综合利用java中的文件输入和输出相 ...