Additive属性动画

简介:

Additive属性动画

 

参考

http://ronnqvi.st/multiple-animations/

 

效果

 

源码

https://github.com/YouXianMing/Animations




//
//  AdditiveAnimationController.m
//  Animations
//
//  Created by YouXianMing on 16/1/21.
//  Copyright © 2016年 YouXianMing. All rights reserved.
//

#import "AdditiveAnimationController.h"
#import "UIView+SetRect.h"

@interface AdditiveAnimationController ()

@property (nonatomic, strong) CALayer  *layer;

@end

@implementation AdditiveAnimationController

- (void)setup {
    
    [super setup];
    
    // http://ronnqvi.st/multiple-animations/
    
    self.layer                 = [CALayer layer];
    self.layer.frame           = CGRectMake(0, 0, 30, 30);
    self.layer.backgroundColor = [UIColor redColor].CGColor;
    self.layer.cornerRadius    = 15.f;
    self.layer.position        = self.contentView.middlePoint;
    [self.contentView.layer addSublayer:self.layer];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapEvent:)];
    [self.contentView addGestureRecognizer:tap];
}

- (void)tapEvent:(UITapGestureRecognizer *)tapGesture {
    
    CGPoint touchPoint      = [tapGesture locationInView:tapGesture.view];
    CGPoint differencePoint = CGPointMake(self.layer.position.x - touchPoint.x,
                                          self.layer.position.y - touchPoint.y);
    
    CALayer *presentationLayer = self.layer.presentationLayer;
    NSLog(@"%@", presentationLayer);
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
    animation.duration          = 1.f;
    animation.timingFunction    = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    animation.additive          = true;
    animation.fromValue         = [NSValue valueWithCGPoint:differencePoint];
    animation.toValue           = [NSValue valueWithCGPoint:CGPointZero];
    
    [CATransaction begin];
    [CATransaction setDisableActions:YES];
    self.layer.position = touchPoint;
    [CATransaction commit];
    
    [self.layer addAnimation:animation forKey:nil];
}

@end

细节




目录
相关文章
|
9天前
|
JavaScript 开发者
HarmonyNext动画大全03-帧动画
HarmonyNext动画大全03-帧动画
12 2
|
API Android开发
Android动画——属性动画
在属性动画中,常用到的API有ValueAnimator,ObjectAnimator。 ValueAnimator:时间引擎,负责计算各个帧的属性值,基本上其他属性动画都会直接或间接继承它; ObjectAnimator: ValueAnimator 的子类,对指定对象的属性执行动画。
157 0
|
XML Java Android开发
Android动画 补间动画
补间动画:属于Android中View动画的一种,就是涵盖了 平移、缩放、旋转 和 透明度四种变化的动画。实现方式有两种:xml文件 和 java代码。 四种补间动画分别为RotateAnimation、ScaleAnimation、TranslateAnimation、AlphaAnimation,他们的父类为Animation。
|
XML Web App开发 编解码
Android动画之帧动画
在Android开发时,为了实现一些动态的炫酷的效果,我们常用到帧动画,View动画(补间动画)和属性动画,今天就来总结下我在使用帧动画的实现方式。
属性动画 - CAAnimationDelegate
属性动画 - CAAnimationDelegate
130 0
|
Android开发 内存技术
Android动画(帧动画、补间动画、属性动画)讲解
帧动画:是一种常见的动画形式(Frame By Frame),其原理是在“连续的关键帧”中分解动画动作,也就是在时间轴的每帧上逐帧绘制不同的内容,使其连续播放而成动画。 补间动画:指的是做FLASH动画时,在两个关键帧中间需要做“补间动画”,才能实现图画的运动; 属性动画:帧动画与补间动画实现了对View进行移动、缩放、旋转和淡入淡出的效果。但对于android开发师来说是不够的,同时移动、缩放、旋转和淡入淡出的效果也不再只是一种视觉上的动画效果了。所以从Android 3.0版本开始,系统给我们提供了一种全新的动画模式,属性动画(property animation)。
332 0
Android动画(帧动画、补间动画、属性动画)讲解
RecyclerView 添加动画
RecyclerView 添加动画
193 0
|
存储 图形学
动画系统中的基础动画
动画系统中的基础动画
172 0
动画系统中的基础动画
|
Android开发 Java 数据格式
Android 基础动画之属性动画详解
在上两篇文章主要介绍了 Android 基础动画之帧动画 以及 Android 基础动画之补间动画 。本篇文章主要介绍的是Android基础动画之 属性动画 。
1133 0
|
XML Android开发 数据格式
Android动画之补间动画详解
一.概念 补间动画是指开发者无需定义动画过程中的每一帧,只需要定义动画的开始和结束两个关键帧,并指定动画变化的时间和方式等,然后交由Android系统进行计算,通过在这两个关键帧之间插入渐变值来实现平滑过渡,从而对View的内容完成一系列的图形变换来实现动画效果,主要包括四种基本效果:透明变化Alpha、大小变化Scale、位移变化Translate、以及旋转变化Route,这四种效果可以动态组合,从而实现复杂灵活的动画。
1249 0