IOS 几种简单常用动画
来源:互联网 发布:组态王软件价格 编辑:程序博客网 时间:2024/06/16 13:46
使用前
需引入QuartzCore
.framework
, 并在相关文件中加入 #import "QuartzCore/QuartzCore
.h
"
定义
shakeFeedbackOverlay为UIImageView
设置
self
.shakeFeedbackOverlay
.alpha
=
0
.0
;
self
.shakeFeedbackOverlay
.layer
.cornerRadius
=
1
0
.0
;
//设置圆角半径
1
、图像左右抖动
CABasicAnimation* shake = [
CABasicAnimation
animationWithKeyPath
:
@"transform.rotation.z"
];
shake
.fromValue
= [
NSNumber
numberWithFloat
:-M_PI/
3
2
];
shake
.toValue
= [
NSNumber
numberWithFloat
:+M_PI/
3
2
];
shake
.duration
=
0
.1
;
shake
.autoreverses
=
YES
;
//是否重复
shake
.repeatCount
=
4
;
[
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
、图像顺时针旋转
CABasicAnimation* shake = [
CABasicAnimation
animationWithKeyPath
:
@"transform.rotation.z"
];
shake
.fromValue
= [
NSNumber
numberWithFloat
:
0
];
shake
.toValue
= [
NSNumber
numberWithFloat
:
2
*M_PI];
shake
.duration
=
0
.8
; shake
.autoreverses
=
NO
;
shake
.repeatCount
=
1
;
[
self
.shakeFeedbackOverlay
.layer
addAnimation
:shake
forKey
:
@"shakeAnimation"
];
self
.shakeFeedbackOverlay
.alpha
=
1
.0
;
[
UIView
animateWithDuration
:
1
0
.0
delay
:
0
.0
options
:
UIViewAnimationOptionCurveEaseIn
|
UIViewAnimationOptionAllowUserInteraction
animations
:^{
self
.shakeFeedbackOverlay
.alpha
=
0
.0
; }
completion
:nil
];
3
、图像关键帧动画
CAKeyframeAnimation
*animation = [
CAKeyframeAnimation
animation
];
CGMutablePathRef
aPath = CGPathCreateMutable();
CGPathMoveToPoint(aPath,
nil
,
2
0
,
2
0
);
CGPathAddCurveToPoint(aPath,
nil
,
1
6
0
,
3
0
,
2
2
0
,
2
2
0
,
2
4
0
,
4
2
0
);
animation
.path
= aPath;
animation
.autoreverses
=
YES
;
animation
.duration
=
2
;
animation
.timingFunction
= [
CAMediaTimingFunction
functionWithName
:kCAMediaTimingFunctionEaseOut];
animation
.rotationMode
=
@"auto"
;
[ballView
.layer
addAnimation
:animation
forKey
:
@"position"
];
4
、组合动画
CAAnimationGroup
CABasicAnimation
*flip = [
CABasicAnimation
animationWithKeyPath
:
@"transform.rotation.y"
];
flip
.toValue
= [NSNumbernumberWithDouble:-M_PI];
CABasicAnimation
*scale= [
CABasicAnimation
animationWithKeyPath
:
@"transform.scale"
];
scale
.toValue
= [NSNumbernumberWithDouble:
1
2
];
scale
.duration
=
1
.5
;
scale
.autoreverses
=
YES
;
CAAnimationGroup
*group = [
CAAnimationGroup
animation
];
group
.animations
= [
NSArray
arrayWithObjects
:flip, scale,
nil
];
group
.timingFunction
= [
CAMediaTimingFunction
functionWithName
:kCAMediaTimingFunctionEaseInEaseOut];
group
.duration
=
3
;
group
.fillMode
= kCAFillModeForwards;
group
.removedOnCompletion
=
NO
;
[ballView
.layer
addAnimation
:group
forKey
:
@"position"
];
5
、指定时间内旋转图片
//启动定时器旋转光圈
- (
void
)startRotate
{
self
.rotateTimer
= [
NSTimer
scheduledTimerWithTimeInterval
:
0
.02
target
:
self
selector
:
@selector
(rotateGraduation)
userInfo
:nil
repeats
:
YES
];
}
//关闭定时器
- (
void
)stopTimer
{
if
([
self
.rotateTimerisValid
])
{
[
self
.rotateTimerinvalidate
];
self
.rotateTimer
=
nil
;
}
}
//旋转动画
- (
void
)rotateGraduation
{
self
.timeCount
--;
if
(
self
.timeCount
==
0
)
{
[
self
stopTimer
];
// doSomeThing //旋转完毕 可以干点别的
self
.timeCount
=
2
5
;
}
else
{
//计算角度 旋转
static
CGFloat
radian =
150
* (
M_2_PI
/
3
6
0
);
CGAffineTransform
transformTmp =
self
.lightImageView
.transform
;
transformTmp = CGAffineTransformRotate(transformTmp, radian);
self
.lightImageView
.transform
= transformTmp;
};
}
调用方法
self
.timeCount
=
2
5
;
//动画执行25次
[
self
startRotate
];
0 0
- IOS 几种简单常用动画
- IOS UITableViewCell常用几种动画效果
- IOS常用的简单动画
- iOS 简单常用动画animation
- iOS开发常用的几种动画效果
- IOS的几种动画及其简单应用
- 几种常用动画总结
- 属性动画的几种简单用途
- 属性动画的几种简单用途
- ios 实现动画的几种方式
- IOS几种实现动画的方式
- iOS常用UI控件属性及简单动画
- IOS常用动画效果
- iOS常用动画
- iOS 常用动画效果
- iOS常用动画
- iOS常用动画
- iOS常用动画
- Python-- easy_install 的安装
- Cocos2dx 学习笔记 -TMX和物理引擎的结合
- 为什么x86模式里BIOS在0x7c00加载MBR
- 【ACM】最大的矩形
- HDU 5194 DZY Loves Balls
- IOS 几种简单常用动画
- UltimateRecyclerView
- 常见的正则表达式总结
- 1 计算机组成原理和系统安装(云计算)
- UML建模快速入门00 Outline
- 如何规划和配置YARN和MapReduce 2
- LeetCode - Construct Binary Tree from Inorder and Postorder Traversal
- Sicily 13290 Play with Strings powered by wangbin
- HDU 5195 DZY Loves Topological Sorting