核心动画(CAKeyframeAnimation)

Main.storyboard

ViewController.m

//

//  ViewController.m

//  8A02.核心动画 - CAKeyframeAnimation

//

//  Created by huan on 16/2/4.

//  Copyright © 2016年 huanxi. All rights reserved.

//

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

//添加一个圆

CGFloat screenW = [UIScreen mainScreen].bounds.size.width;

UIView *circleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenW, screenW)];

circleView.backgroundColor = [UIColor yellowColor];

//设置圆角

circleView.layer.cornerRadius = screenW * 0.5;

[self.view addSubview:circleView];

//把图片移到顶部

[self.view bringSubviewToFront:self.imageView];

}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

//学习帧动画

//创建一个帧动画

CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];

animation.keyPath = @"position";

//设置动画执行路径 指定四个点

NSValue *value1 = [NSValue valueWithCGPoint:CGPointMake(50, 50)];

NSValue *value2 = [NSValue valueWithCGPoint:CGPointMake(250, 50)];

NSValue *value3 = [NSValue valueWithCGPoint:CGPointMake(250, 250)];

NSValue *value4 = [NSValue valueWithCGPoint:CGPointMake(50, 250)];

//数组第一个是"开始状态" 最后一个是“结束状态”

animation.values = @[value1, value2, value3, value4, value1];

//设置时间

animation.duration = 3;

//设置动画节奏

//    kCAMediaTimingFunctionEaseIn 先慢后快

//    kCAMediaTimingFunctionEaseOut 先慢后快

//    kCAMediaTimingFunctionEaseOut 线性匀速

//    kCAMediaTimingFunctionEaseInEaseOut 中间快两边慢

animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

#warning 内部的path的优先级大于values优先级

//设置路径

CGMutablePathRef path = CGPathCreateMutable();

CGFloat screenW = [UIScreen mainScreen].bounds.size.width;

CGPathAddEllipseInRect(path, NULL, CGRectMake(0, 0, screenW, screenW));

animation.path = path;

//c语言的数据类型,如果create/copy/retain 创建要释放

//添加动画

[self.imageView.layer addAnimation:animation forKey:nil];

}

@end

结果

时间: 2024-08-24 14:29:29

核心动画(CAKeyframeAnimation)的相关文章

猫猫学IOS(四十)UI之核心动画_抖动效果_CAKeyframeAnimation

猫猫分享,必须精品 原创文章,欢迎转载.转载请注明:翟乃玉的博客 地址:http://blog.csdn.net/u013357243?viewmode=contents 效果: 效果一: 效果二: 代码: // // NYViewController.m // 图片抖动 // // Created by apple on 15-5-8. // Copyright (c) 2015年 znycat. All rights reserved. // #import "NYViewControlle

核心动画(关键帧动画)-转

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

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

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

IOS 核心动画之CAKeyframeAnimation

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

ios开发核心动画五:图标抖动效果--CAKeyframeAnimation

#import "ViewController.h" #define angle2Rad(angle) ((angle) / 180.0 * M_PI) @interface ViewController () @property (weak, nonatomic) IBOutlet UIImageView *imageV; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //

IOS 核心动画之CAKeyframeAnimation - iBaby

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

核心动画(CAKeyframeAnimation,CABasicAnimation)

一,核心动画常用的三种例子 view的核心动画其体现就是把view按照指定好的路径进行运动,针对的是view的整体. [view.layer addAnimation:动画路径 forKey:@"绑定动画路径的键值"]; A,view的整体按照指定好的路径进行运动,里面的子view固定在view不动情况: 1)创建需要显示的动画路径(动画路径可以是UIBezierPath,也可以是某个参数或点坐标等,如果是后者,则常常设置fromValue和toValue,通过它们来确定动画路径) C

核心动画

在ViewController.m中. @interface ViewController ()@property(nonatomic, strong) UIView * MyView;@end @implementation ViewController - (void)viewDidLoad {    [super viewDidLoad];            self.MyView = [[UIView alloc] initWithFrame:CGRectMake(100, 100,

IOS-CoreAnimation(核心动画)

一.核心动画 1.Core Animation是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍,使用它需要先添加QuartzCore.framework和引入对应的框架<QuartzCore/QuartzCore.h> 2.开发步骤: ①初始化一个动画对象(CAAnimation)并设置一些动画相关属性 ②添加动画对象到层(CALayer)中,开始执行动画 3.CALayer中很多属性都可以通过CAAnimation实现动画效果,包括:opacity.posi