zoukankan      html  css  js  c++  java
  • CoreAnimation-06-CAKeyframeAnimation 相关代码

      • - (void)awakeFromNib{    

            iMV = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];

            iMV.image = [UIImage imageNamed:@"c"];

            [self addSubview:iMV];

            NSLog(@"%@",NSStringFromCGRect([[self.subviews firstObject] layer].bounds));

        }

      • 使用成员属性保存贝瑟尔路径
      @property (nonatomic, strong) UIBezierPath *path;
      • 监听触摸事件的状态,绘制贝瑟尔曲线

        • 开始
        //确定起点
        - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
        {
        	//获取当前触摸点
        	UITouch *touch = [touches anyObject];
        	CGPoint curretnPoint = [touch locationInView:self];
        
        	//创建路径
        	UIBezierPath *path = [UIBezierPath bezierPath];
        	[path moveToPoint:curretnPoint];
        	//保存路径
        	self.path = path;
        }
        • 移动
        //添加线条
        - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
        {
        	//获取当前触摸点
        	UITouch *touch = [touches anyObject];
        	CGPoint currentPoint = [touch locationInView:self];
        	//添加线条
        	[self.path addLineToPoint:currentPoint];
        	//重绘,将曲线显示到图层上
        	[self setNeedsDisplay];
        }
        • 结束(创建动画)
        - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
        {
        	//创建动画
        	CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
        
        	//指定执行动画的属性,
        	animation.keyPath = @"position";
        	//设置动画的执行路径
        	animation.path = self.path.CGPath;
        
        	//设置动画的执行时间
        	animation.duration = 1;
        	//设置动画的重复次数
        	animation.repeatCount = MAXFLOAT;
        
        	//将动画添加到对应的图层上
        	[[[self.subviews firstObject] layer] addAnimation:animation forKey:nil];
        }
      • 将路径显示到图层上

      //绘制路径
      - (void)drawRect:(CGRect)rect
      {
      	[self.path stroke];
      }
     
     
  • 相关阅读:
    linux中grep用法(“或”、“与”)
    mac 常用开发软件列表
    Devops实战(四)Rancher的部署与安装详解
    Devops实战(三)Kubenets与minikube的安装以及使用实战
    intel 无线网卡 AC8260 周期性跳ping(高延迟)解决方案
    确定了,回归吧,19,20就当换了换环境,该努力了。
    win10下用Linux搭建python&nodejs开发环境
    pict总结
    移动无线常用测试工具
    游戏测试工具
  • 原文地址:https://www.cnblogs.com/yxt9322yxt/p/4772339.html
Copyright © 2011-2022 走看看