iOS动画 CABasicAnimation
来源:互联网 发布:淘宝推广 猪八戒网 编辑:程序博客网 时间:2024/06/05 08:02
首先引入框架:QuartzCore.framework
在头文件声明:CALayer *logoLayer
注意fromValue和toValue是参考的控件的中间位置
{
//界限
CABasicAnimation *boundsAnimation = [CABasicAnimationanimationWithKeyPath:@"bounds"];
boundsAnimation.fromValue = [NSValue valueWithCGRect: logoLayer.bounds];
boundsAnimation.toValue = [NSValue valueWithCGRect:CGRectZero];
//透明度变化
CABasicAnimation *opacityAnimation = [CABasicAnimationanimationWithKeyPath:@"opacity"];
opacityAnimation.fromValue = [NSNumber numberWithFloat:1.0];
opacityAnimation.toValue = [NSNumber numberWithFloat:0.5];
//位置移动
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
animation.fromValue = [NSValue valueWithCGPoint: logoLayer.position];
CGPoint toPoint = logoLayer.position;
toPoint.x += 180;
animation.toValue = [NSValue valueWithCGPoint:toPoint];
//旋转动画
CABasicAnimation* rotationAnimation =
[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];//"z"还可以是“x”“y”,表示沿z轴旋转
rotationAnimation.toValue = [NSNumber numberWithFloat:(2 * M_PI) * 3];
// 3 is the number of 360 degree rotations
// Make the rotation animation duration slightly less than the other animations to give it the feel
// that it pauses at its largest scale value
rotationAnimation.duration = 2.0f;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; //缓入缓出
//缩放动画
CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.fromValue = [NSNumber numberWithFloat:0.0];
scaleAnimation.toValue = [NSNumber numberWithFloat:1.0];
scaleAnimation.duration = 2.0f;
scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
animationGroup.duration = 2.0f;
animationGroup.autoreverses = YES; //是否重播,原动画的倒播
animationGroup.repeatCount = NSNotFound;//HUGE_VALF; //HUGE_VALF,源自math.h
[animationGroup setAnimations:[NSArray arrayWithObjects:rotationAnimation, scaleAnimation, nil]];
//将上述两个动画编组
[logoLayer addAnimation:animationGroup forKey:@"animationGroup"];
}
//去掉所有动画
[logoLayer removeAllAnimations];
//去掉key动画
[logoLayer removeAnimationForKey:@"animationGroup"];
- iOS CABasicAnimation 缩放动画
- iOS动画 CABasicAnimation
- iOS动画 CABasicAnimation
- iOS 核心动画之CABasicAnimation
- iOS核心动画之CABasicAnimation
- iOS CoreAnimation 基础动画CABasicAnimation
- IOS 核心动画值CABasicAnimation
- 【iOS开发-动画】CABasicAnimation实现动画
- iOS:核心动画之基本动画CABasicAnimation
- iOS核心动画 Core Animation2-CABasicAnimation
- iOS-核心动画(二)CABasicAnimation
- iOS动画(一):拍电影与CABasicAnimation
- iOS动画(一):拍电影与CABasicAnimation
- iOS动画(一):拍电影与CABasicAnimation
- IOS动画之 CAKeyframeAnimation跟CABasicAnimation
- iOS动画详解 (CABasicAnimation,UIBezierPath,CAShapeLayer)
- iOS CoreAnimation之CABasicAnimation:文字路径动画
- iOS动画(一):拍电影与CABasicAnimation
- QQ消息提醒小球OC 详解
- HDU 5500 Reorder the Books(贪心+思维)
- Python包的安装
- Java中枚举类型Enum的一种使用方式
- Linux如何查看端口被哪个进程占用?
- iOS动画 CABasicAnimation
- window下eclipse提交hadoop作业遇到的坑
- Log4j2(一)Architecture
- Codefroces384B
- 《JavaScript权威指南》阅读笔记(2)
- HTML5的 input:file上传类型控制
- TODOList
- C++各容器的语法及特点
- MongoDB——数据库操作