核心动画-06-关键帧动画-day4

  1 //
  2 //  ViewController.m
  3 //  06 关键帧动画
  4 //
  5 //  Created by ZhuJiaCong on 16/4/18.
  6 //  Copyright © 2016年 wxhl. All rights reserved.
  7 //
  8
  9 #import "ViewController.h"
 10
 11 @interface ViewController ()
 12 {
 13     CGMutablePathRef _path;
 14 }
 15 @property (weak, nonatomic) IBOutlet UIView *redView;
 16
 17 @end
 18
 19 @implementation ViewController
 20
 21 - (void)viewDidLoad {
 22     [super viewDidLoad];
 23
 24     _redView.layer.cornerRadius = 10;
 25
 26
 27
 28 }
 29
 30
 31 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
 32
 33     //关键帧动画
 34 //    CAKeyframeAnimation *keyFrame = [CAKeyframeAnimation animationWithKeyPath:@"position"];
 35 //
 36 //    //创建帧
 37 //    CGPoint point1 = CGPointMake(100, 100);
 38 //    CGPoint point2 = CGPointMake(150, 100);
 39 //    CGPoint point3 = CGPointMake(100, 150);
 40 //    CGPoint point4 = CGPointMake(150, 150);
 41 //    CGPoint point5 = CGPointMake(200, 100);
 42 //    CGPoint point6 = CGPointMake(100, 200);
 43 //
 44 //
 45 //    NSArray *array = @[[NSValue valueWithCGPoint:point1],
 46 //                       [NSValue valueWithCGPoint:point2],
 47 //                       [NSValue valueWithCGPoint:point3],
 48 //                       [NSValue valueWithCGPoint:point4],
 49 //                       [NSValue valueWithCGPoint:point5],
 50 //                       [NSValue valueWithCGPoint:point6]
 51 //                       ];
 52 //
 53 //    keyFrame.values = array;
 54 //
 55 //    keyFrame.duration = 3;
 56 //
 57 //    //将动画添加到图层上去
 58 //    [_redView.layer addAnimation:keyFrame forKey:@"keyFrame"];
 59
 60
 61
 62
 63     if (_path) {
 64         CGPathRelease(_path);
 65         _path = NULL;
 66     }
 67
 68     //创建路径
 69     _path = CGPathCreateMutable();
 70     //设置路径起点
 71     UITouch *touch = [touches anyObject];
 72     CGPoint location = [touch locationInView:self.view];
 73     CGPathMoveToPoint(_path, NULL, location.x, location.y);
 74
 75 }
 76
 77 - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
 78     //获取触摸点 添加路径点
 79     UITouch *touch = [touches anyObject];
 80     CGPoint location = [touch locationInView:self.view];
 81
 82     CGPathAddLineToPoint(_path, NULL, location.x, location.y);
 83
 84 }
 85
 86 - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
 87
 88     //执行动画
 89     CAKeyframeAnimation *keyFrame = [CAKeyframeAnimation animationWithKeyPath:@"position"];
 90     keyFrame.path = _path;
 91
 92
 93     keyFrame.duration = 5;
 94
 95
 96
 97     //速度控制函数
 98     keyFrame.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
 99
100
101     [_redView.layer addAnimation:keyFrame forKey:nil];
102
103 }
104
105
106
107 - (void)didReceiveMemoryWarning {
108     [super didReceiveMemoryWarning];
109     // Dispose of any resources that can be recreated.
110 }
111
112 @end
时间: 2024-07-30 11:06:52

核心动画-06-关键帧动画-day4的相关文章

核心动画基础动画(CABasicAnimation)关键帧动画

1.在iOS中核心动画分为几类: 基础动画(CABasicAnimation) 关键帧动画(CAKeyframeAnimation) 动画组(CAAnimationGroup) 转场动画(CATransition) 2.CAAnimation:核心动画的基础类,不能直接使用,负责动画运行时间,速度的控制,本身实现了CAMediaTiming协议 3.CAPropertyAnimation:属性动画也是基类(通过属性进行动画设置,注意是动画属性),不能直接使用. CABasicAnimation:

iOS:核心动画之关键帧动画CAKeyframeAnimation

CAKeyframeAnimation——关键帧动画 关键帧动画,也是CAPropertyAnimation的子类,与CABasicAnimation的区别是: –CABasicAnimation只能从一个数值(fromValue)变到另一个数值(toValue),而CAKeyframeAnimation会使用一个NSArray保存这些数值 – 属性说明: –values:上述的NSArray对象.里面的元素称为“关键帧”(keyframe).动画对象会在指定的时间(duration)内,依次显

显示动画,隐式动画、关键帧动画

概要 一些简单的动画代理学习例子,包括显示.隐式.关键帧.关键帧路径四类动画.(感觉这个动画太复杂,学习简单的例子没继续了) 结果展示 流程概要 见代码 主要代码 // // ViewController.m // Animation // // Created by arbboter on 14/12/20. // Copyright (c) 2014年 arbboter. All rights reserved. // #import "ViewController.h" @int

WPF动画之关键帧动画(2)

XAML代码: 1 <Window x:Class="关键帧动画.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 Title="MainWindow" Height="350"

ios核心动画之关键帧动画

1 #import "NJViewController.h" 2 3 @interface NJViewController () 4 5 @property (weak, nonatomic) IBOutlet UIView *customView; 6 - (IBAction)btnClick:(id)sender; 7 @end 8 9 @implementation NJViewController 10 11 - (void)touchesBegan:(NSSet *)tou

iOS学习笔记28-基础动画和关键帧动画

首先创建layer CALayer *layer = [CALayer layer]; layer.bounds = CGRectMake(0, 0, 100, 100); layer.position = CGPointMake(100, 100); layer.backgroundColor = [UIColor yellowColor].CGColor; [self.view.layer addSublayer:layer]; self.layer = layer; 设置点击事件 -(vo

iOS开发UI篇—核心动画(关键帧动画)

iOS开发UI篇—核心动画(关键帧动画) 一.简单介绍 是CApropertyAnimation的子类,跟CABasicAnimation的区别是:CABasicAnimation只能从一个数值(fromValue)变到另一个数值(toValue),而CAKeyframeAnimation会使用一个NSArray保存这些数值 属性解析: values:就是上述的NSArray对象.里面的元素称为”关键帧”(keyframe).动画对象会在指定的时间(duration)内,依次显示values数组

核心动画(关键帧动画)

核心动画(关键帧动画) 一.简单介绍 是CApropertyAnimation的子类,跟CABasicAnimation的区别是:CABasicAnimation只能从一个数值(fromValue)变到另一个数值(toValue),而CAKeyframeAnimation会使用一个NSArray保存这些数值 属性解析: values:就是上述的NSArray对象.里面的元素称为”关键帧”(keyframe).动画对象会在指定的时间(duration)内,依次显示values数组中的每一个关键帧

iOS开发UI篇—核心动画(关键帧动画)(转摘)

iOS开发UI篇—核心动画(关键帧动画) 一.简单介绍 是CApropertyAnimation的子类,跟CABasicAnimation的区别是:CABasicAnimation只能从一个数值(fromValue)变到另一个数值(toValue),而CAKeyframeAnimation会使用一个NSArray保存这些数值 属性解析: values:就是上述的NSArray对象.里面的元素称为”关键帧”(keyframe).动画对象会在指定的时间(duration)内,依次显示values数组

iOS核心动画以及UIView动画的介绍

我们看到很多App带有绚丽狂拽的特效,别出心裁的控件设计,很大程度上提高了用户体验,在增加了实用性的同时,也赋予了app无限的生命力.这些华丽的效果很多都是基于iOS的核心动画原理实现的,本文介绍一些iOS开发中最基本的动画效果实现,掌握了基本属性,才可以绘制出更华丽的效果. 一.概念扩充  1.核心动画: Core Animation,它是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍. Core Animation可以用在Mac OS X和iOS平台.在iO