使用前

        需引入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. Java [leetcode 3] Longest Substring Without Repeating Characters

    问题描述: Given a string, find the length of the longest substring without repeating characters. For exa ...

  2. poj 2063 Investment

    题意:给定一个初始资金capital,然后给定d种投资方案,每种投资方案中有投资额value[i](是1000的倍数)和利息interest[i],每年的投资就可以拿到全部利息,然后累加起来继续投资利 ...

  3. 【JS】js获得下拉列表选中项的值和id

    function tijiao(){ var elem = document.getElementById("dish_sort"); var index=elem.selecte ...

  4. 本博客迁移到Github,之后停止更新

    本博客之后停止更新或者更新不是很及时,关注博客请移步   http://waylife.github.io 或者 http://blog.13kbook.com   谢谢支持. Update Time ...

  5. SQL Server优化50法(转)

    虽然查询速度慢的原因很多,但是如果通过一定的优化,也可以使查询问题得到一定程度的解决. 查询速度慢的原因很多,常见如下几种: 没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺陷) I/ ...

  6. LightOJ 1427 -Repository(ac自动机)

    题意: 求每个模式串在母串中出现的次数 #include <map> #include <set> #include <list> #include <cma ...

  7. bjfu1100 圆环

    这题也是2011百度之星的一道题.知道做法后代码极简单. 不过我做完后随便上网搜了一下,发现竟然还有很多不同的做法.别的做法我就不管了,我只把我的做法的原理说清楚.我做题时是按如下顺序逐步找到规律的: ...

  8. 不知道帐号密码的情况下完全重装Mac Min的OS X10.7系统

    现状: 1.原系统OS X 10.7 2.老账号不知道密码 3.Mac小盒子 目的: 1.删除老账号 2.更新系统到10.9以上 尝试过程1: 1.按住option键 + 开机 2.选择“磁盘工具” ...

  9. CentOS VPS创建pptpd VPN服务

    原文地址http://www.hi-vps.com/wiki/doku.php?id=xen_vps_centos6_install_pptpd CentOS VPS创建pptpd VPN服务 Xen ...

  10. 使用Ant发布hadoop代码到服务器

    首先,搭建Ant环境: 1.1.下载antzip包,可以直接从官网下,也可以从我的csdn账号下载,这里我使用的Ant版本是:apache-ant-1.8.4-bin CSDN Ant 所需jar包下 ...