//
// ViewController.m
// 30-核心动画
//
// #import "ViewController.h"
@interface ViewController ()
@property(nonatomic,weak)CALayer *layer;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIView *redView =[[UIView alloc] init];
redView.frame =CGRectMake(100, 100, 20, 20);
redView.backgroundColor =[UIColor redColor];
self.layer=redView.layer ;
[self.view addSubview:redView];
} - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//组动画
CAAnimationGroup *group = [[CAAnimationGroup alloc] init];
//创建动画对象 (做什么动画)
CABasicAnimation *anim = [[CABasicAnimation alloc]init];
anim.keyPath = @"transform.rotation";
anim.byValue =@(2*M_PI*10);
CAKeyframeAnimation *anim1=[[CAKeyframeAnimation alloc] init];
anim1.keyPath = @"position";
UIBezierPath * path=[UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:100 startAngle:0 endAngle:2*M_PI clockwise:1];
anim1.path = path.CGPath;
group.animations=@[anim,anim1];
group.duration = 3;
group.repeatCount = INT_MAX; // 重复的次数
//怎么做动画
//添加动画(对谁做动画)
[self.layer addAnimation:group forKey:nil];
}
//关键帧
-(void)test2{
//关键帧
//创建动画对象 (做什么动画)
CAKeyframeAnimation *anim = [[CAKeyframeAnimation alloc] init];
//怎么做动画
anim.keyPath=@"position";
/* NSValue *v1 =[NSValue valueWithCGPoint:CGPointMake(100, 100)];
NSValue *v2 =[NSValue valueWithCGPoint:CGPointMake(150, 100)];
NSValue *v3 =[NSValue valueWithCGPoint:CGPointMake(100, 150)];
NSValue *v4 =[NSValue valueWithCGPoint:CGPointMake(150,150 )];
anim.values =@[v1,v2,v3,v4];
*/
UIBezierPath * path=[UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:100 startAngle:0 endAngle:2*M_PI clockwise:1];
anim.path = path.CGPath;
anim.duration = 2;
anim.repeatCount = INT_MAX; // 重复的次数
//添加动画(对谁做动画)
[self.layer addAnimation:anim forKey:nil];
}
//基础动画
-(void)testbaseAnimation{
//创建动画对象 (做什么动画)
CABasicAnimation *animation = [[CABasicAnimation alloc] init];
//怎么做动画
animation.keyPath = @"position.x";
/*animation.fromValue =@(10); 从哪
animation.toValue = @(300); 到哪
*/
//每次加10px
animation.byValue = @(10);
//不回去原来的地方
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion=NO;
//添加动画(对谁做动画)
[self.layer addAnimation:animation forKey:nil];
}
@end

// LJView.m
// 30-核心动画
//
// #import "LJView.h" @implementation LJView /*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
*/
- (void)drawRect:(CGRect)rect {
// Drawing code UIBezierPath * path=[UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:100 startAngle:0 endAngle:2*M_PI clockwise:1];
[path stroke]; } @end

最新文章

  1. HTTPS, SPDY和 HTTP/2性能的简单对比
  2. $.when().then()
  3. Gradle中使用idea插件的一些实践
  4. Apache配置命令
  5. windows核心编程-信号量(semaphore)
  6. [C++程序设计]函数的递归调用
  7. spring的作用及优势---第一个spring示例
  8. javascript——ajax应用
  9. Eclipse中使用Maven新建 Servlet 2.5的 SpringMVC项目
  10. Groovy闭包详解
  11. UI组件--element-ui--Upload多组件自定义上传
  12. 原生JS-旋转木马
  13. Java 生成三位随机数
  14. ECC校验
  15. Seaborn-05-Pairplot多变量图
  16. Vs.net 常用命令行
  17. 合并excel的多个sheet
  18. 数据类型转换(计算mac地址)
  19. 剑指offer-第三章高质量代码(树的子结构)
  20. Win8.1和office2013使用电话激活步骤

热门文章

  1. crontab执行不生效
  2. 基础篇之DOS命令
  3. golang json化时允许赋予默认值
  4. xlsx 前端导出Excel
  5. 源码安装pg9.6
  6. MySQL系列-详解mysql数据类型
  7. 常用的js优秀框架个人记录
  8. noi 1.1 6 空格分隔输出
  9. css 伪类实现渐变线条
  10. php对接java接口