IOS中的动画属性

核心动画

特点 1. 自己去 自己可以回来
    2. 动画移动的图层, 真实的位置 没有改变

CALayer

基本属性

backergroundColor 背景颜色 [UIColor redColor].CGColor
anchorPoint 锚点CGPoint值得范围是0到1之间
position 位置 CGPoint
bounds 大小 CGRect
opacity 透明度
contents 内容id类型

其他属性

边框

borderWidth 边框宽度
borderColor 边框颜色

阴影

shadowColor 阴影颜色
shadowOffset 阴影位置
shadowRadius 阴影半径
==需要设置阴影的透明度==
shadowOpacity 阴影透明度

圆角

cornerRadius 设置圆角
masksToBounds 周围的遮罩 ==如果去掉遮罩那么阴影效果就不会显示==

隐式动画

自带隐式动画,不过可以手动关闭

[CATransaction begin];          开启事务
[CATransaction setDisableActions:YES];         关闭动画
[CATransaction commit];       提交事物

Transform属性

self.layer.transform = CATransform3DTranslate(self.layer.transform, 30, 0, 0);   平移
self.layer.transform = CATransform3DScale(self.layer.transform, 0.5, 0.5, 0);    缩放
self.layer.transform = CATransform3DRotate(self.layer.transform, M_PI_4, 1, 1, 1);  旋转

基本动画(CABasicAnimation)

因为是NSOBjiet的分类所以不需要设置代理
repeatCount 循环次数
duration 单次运行完毕所需时间

Position(X轴 Y轴)

CABasicAnimation  *basic = [CABasicAnimation animationWithKeyPath:@"position.y"],
 key:表示你想让它产生那个属性的动画,    position界面的移动使用
basic.toValue = [NSValue valueWithCGPoint:CGPointMake(200, 500)];  移动的位置

basic.removedOnCompletion = NO;   到了那个移动位置后,是否返回
basic.fillMode = kCAFillModeForwards; 动画的阶段模式,在动画还没开始前  和上面的一起搭配使用,固定用法

Transform(Rotation And Scale)

CABasicAnimation *basic = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];   旋转
basic.toValue = @(M_PI * 2.5);  设置属性  即旋转的角度
[self.layer addAnimation:basic forKey:nil];  需要添加到layer上面
CABasicAnimation *basic = [CABasicAnimation animationWithKeyPath:@"transform.scale"];     缩放

    basic.toValue = @(0.5);                     设置属性
    basic.repeatCount = MAXFLOAT;  
    basic.duration = 2.0;
    [self.layer addAnimation:basic forKey:nil]; 添加

关键帧动画(CAKeyframeAnimation)

Values 属性可以包含多个动作
Path 属性可以设置他的移动路径

沿着固定的点进行移动
CAKeyframeAnimation *key = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    
//设置属性
NSValue *value1 =  [NSValue valueWithCGPoint:CGPointMake(30, 30)];
NSValue *value2 =  [NSValue valueWithCGPoint:CGPointMake(30, 500)];
    
NSValue *value3 =  [NSValue valueWithCGPoint:CGPointMake(360, 500)];
    
NSValue *value4 =  [NSValue valueWithCGPoint:CGPointMake(360, 30)];
    
    
key.values = @[value1,value2,value3,value4,value1];
key.repeatCount = MAXFLOAT;
key.duration = 3.0;
    
//2.添加
[self.layer addAnimation:key forKey:nil];
沿绘制路径移动
CAKeyframeAnimation *key = [CAKeyframeAnimation animationWithKeyPath:@"position"];
        
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(30, 400, 100, 300)];
    
key.path = path.CGPath;
key.duration = 2.0;
    
//2.添加
[self.layer addAnimation:key forKey:nil];
平面的抖动 (通过旋转实现)
CAKeyframeAnimation *key = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];
        
key.values = @[@(-M_PI_4 * 0.03),@(M_PI_4 * 0.03),@(M_PI_4 * 0.03)];
    
key.repeatCount = 30;
    
//2.添加
[self.layer addAnimation:key forKey:nil];

转场动画(CATransition)

CATransition *sition = [CATransition animation];
 //设置属性
    //样式
sition.type = kCATransitionMoveIn;
    //方向
sition.subtype = kCATransitionFromBottom;
        
[self.myImageView.layer addAnimation:sition forKey:nil];

组动画(CAAnimationGroup)

//1.创建动画对象
    CAAnimationGroup *group = [CAAnimationGroup animation];
       
//1.创建动画
CAKeyframeAnimation *key = [CAKeyframeAnimation animationWithKeyPath:@"position"];   
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(30, 300, 300, 200)];    
key.path = path.CGPath;

     
//1.创建动画对象
CABasicAnimation *basic = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
//设置属性
basic.toValue = @(0.1);
   
    
//1.旋转
//1.创建动画 基本动画 transform.rotation 默认是绕着Z轴
CABasicAnimation *basic1 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];    
//设置属性
basic1.toValue = @(M_PI * 10);
    
    
//包含多个动画对象
group.animations = @[key,basic,basic1];    
group.duration = 3;
group.repeatCount = 30;
   
//2.添加动画
[self.layer addAnimation:group forKey:nil];

[TOC]

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 12,732评论 6 30
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 10,569评论 5 13
  • 书写的很好,翻译的也棒!感谢译者,感谢感谢! iOS-Core-Animation-Advanced-Techni...
    钱嘘嘘阅读 6,906评论 0 6
  • Core Animation Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,...
    45b645c5912e阅读 8,233评论 0 21
  • "小画板程序"完成"小画板"程序。 下载地址:http://git.oschina.net/changyou/my...
    _浅墨_阅读 4,019评论 0 5

友情链接更多精彩内容