使用前

        需引入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. 推荐 15 个 Angular.js 应用扩展指令(参考应用)

    几天前我们看到Angular 1.4.0发布了-一个以社团为驱动的发布版本涵盖了400多个GitHub的提交,增加了对特性的提升,比如动画,以及可用性. 官方新闻发布稿 覆盖了绝大部分,这同样值得放于 ...

  2. AngularJS:实现动态添加输入控件功能(转)

    http://www.cnblogs.com/ilovewindy/p/3849428.html <!DOCTYPE html> <html> <head> < ...

  3. getView 数据最后加一项

    if (position != count-1) {      viewHolder.imgLineEnd.setVisibility(View.GONE); } else {       viewH ...

  4. 《零成本实现Web自动化测试--基于Selenium》第三章 Selenium-IDE

    1.简介 Selenium-IDE(集成开发环境)是一种开发selenium测试案例的工具.是一种易用的Firefox插件.你可以通过文字菜单,在当前页面上选择一个UI元素,接着挑选与UI元素相关的s ...

  5. Authentication with SignalR and OAuth Bearer Token

    Authentication with SignalR and OAuth Bearer Token Authenticating connections to SignalR is not as e ...

  6. C# 中如何判断某个字符串是否为空的方法 分享了三个方法来判断字

    1. 三种常用的字符串判空串方法:Length法:bool isEmpty = (str.Length == 0);Empty法:bool isEmpty = (str == String.Empty ...

  7. redis集群的搭建

    1.首先下载好软件包 #cd /opt/tzr/ #wget http://redis.googlecode.com/files/redis-2.6.11.tar.gz #mkdir /opt/tzr ...

  8. Spring 中context.start作用

    我们经常会看到 如下代码 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(configPath. ...

  9. javadoc注释规范

    javadoc做注释 一. Java 文档 // 注释一行 /* ...... */ 注释若干行 /** ...... */ 注释若干行,并写入 javadoc 文档 通常这种注释的多行写法如下: / ...

  10. 《Java数据结构与算法》笔记-CH2无序数组

    /** * 本章目标: * 1.自制数组类 * 2.有序数组:按关键字升降序排列:二分法查找 * 3.分析有序数组.大O表示法 */ /** * 自制数组类 书中有的地方有错误,本程序以修改 */ c ...