iOS常用动画代码
使用前
需引入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常用动画代码的更多相关文章
- IOS 制作动画代码和 设置控件透明度
方式1: //animateWithDuration用1秒钟的时间,执行代码 [UIView animateWithDuration:1.0 animations:^{ //存放需要执行的动画代码 s ...
- ios常用动画
// // CoreAnimationEffect.h // CoreAnimationEffect // // Created by VincentXue on 13-1-19. // Copyri ...
- 【转】IOS 30多个iOS常用动画,带详细注释
原文: http://blog.csdn.net/zhibudefeng/article/details/8691567 CoreAnimationEffect.h 文件 // CoreAnimati ...
- iOS常用动画-b
CoreAnimationEffect.h // CoreAnimationEffect // // Created by VincentXue on 13-1-19. // Copyright ...
- 30多种iOS常用动画
转自:http://blog.csdn.net/zhibudefeng/article/details/8691567 // // CoreAnimationEffect.h // CoreAni ...
- iOS常用动画 类封装
//这是一个很好的动画封装类 很容易明白很详细 和大家分享 // CoreAnimationEffect.h // CoreAnimationEffect // // Created by Vince ...
- iOS 常用开源代码整理
本文章不定期整理. 1.AFNetworking AFNetworking 采用 NSURLConnection + NSOperation, 主要方便与服务端 API 进行数据交换, 操作简单, 功 ...
- iOS常用的代码块整理
strong @property (nonatomic,strong) <#Class#> *<#object#>; weak @property (nonatomic,wea ...
- IOS 常用功能代码
1. 关闭/隐藏键盘 resignFirstResponder 响应view的方法 -(IBAction)fname:(id)sender{ [sender resignFirstResponder] ...
随机推荐
- Java [Leetcode 102]Binary Tree Level Order Traversal
题目描述: Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to ...
- Table '.\mysql\proc' is marked as crashed and should be repaired 报错
Table '.\mysql\proc' is marked as crashed and should be repaired 报错 解决方法: 找到mysql的安装目录的bin/myisamchk ...
- Android 长按setOnItemLongClickListener 注意细节
Java代码 gridview.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean ...
- [Everyday Mathematics]20150203
设 $f$ 在 $\bbR$ 上连续可导, 且 $\dps{f'\sex{\frac{1}{2}}=0}$. 试证: $$\bex \exists\ \xi\in \sex{0,\frac{1}{2} ...
- Android之APK文件签名——keytool和jarsigner
一.生成密钥库将位置定位在jdk的bin文件中,输入以下命名行:keytool -genkey -alias ChangeBackgroundWidget.keystore -keyalg RSA - ...
- 对delegate进行扩展 打造通用的"计时完成"方法 z
让用户尽量少打字 每次让用户输入这么多信息的确很糟糕, 可以改进一下设计: 服务器IP和用户名可以存放在配置文件里面, 初始化的时候默认加载到相应的文本框中; 从安全角度考虑, 密码必须经过用户手动输 ...
- Asp.net TextBox常规输入验证
Asp.net TextBox只能输入数字<asp:textbox id="TextBox1" onkeyup="if(isNaN(value))execComma ...
- 无序数组a,求a[i]-a[j]的最大值,且i<j
一道面试题:对于无序数组a,求a[i]-a[j]的最大值,其中i<j package test; import java.util.Arrays; public class FindMax { ...
- HDU 3311 Dig The Wells(斯坦纳树)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3311 [题意] 给定k座庙,n个其他点,m条边,点权代表挖井费用,边权代表连边费用,问使得k座庙里 ...
- [转] Web前端优化之 Cookie篇
原文链接: http://lunax.info/archives/3095.html Web 前端优化最佳实践第三部分面向 Cookie .目前只有 2 条实践规则. 1. 缩小 Cookie (Re ...