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

细节




目录
相关文章
|
5月前
|
JavaScript 开发者
HarmonyNext动画大全03-帧动画
HarmonyNext动画大全03-帧动画
41 2
|
API Android开发
Android动画——属性动画
在属性动画中,常用到的API有ValueAnimator,ObjectAnimator。 ValueAnimator:时间引擎,负责计算各个帧的属性值,基本上其他属性动画都会直接或间接继承它; ObjectAnimator: ValueAnimator 的子类,对指定对象的属性执行动画。
206 0
|
前端开发 开发工具
教你用HTML+CSS实现百叶窗动画效果
我们浏览网页的时候总能看见一些炫酷的特效,比如百叶窗效果,本文我们就用HTML+CSS制作一个百叶窗小项目,适合刚学前端的小伙伴,使用代码简单易懂,很容易上手,学习完本文后,相信你也能敲出来属于自己的百叶窗效果,改变图片及相应盒子的大小,有女朋友的可以试着放几张在一起的照片,也是一件非常浪漫的事
627 0
教你用HTML+CSS实现百叶窗动画效果
属性动画 - CAAnimationDelegate
属性动画 - CAAnimationDelegate
149 0
|
Android开发 内存技术
Android动画(帧动画、补间动画、属性动画)讲解
帧动画:是一种常见的动画形式(Frame By Frame),其原理是在“连续的关键帧”中分解动画动作,也就是在时间轴的每帧上逐帧绘制不同的内容,使其连续播放而成动画。 补间动画:指的是做FLASH动画时,在两个关键帧中间需要做“补间动画”,才能实现图画的运动; 属性动画:帧动画与补间动画实现了对View进行移动、缩放、旋转和淡入淡出的效果。但对于android开发师来说是不够的,同时移动、缩放、旋转和淡入淡出的效果也不再只是一种视觉上的动画效果了。所以从Android 3.0版本开始,系统给我们提供了一种全新的动画模式,属性动画(property animation)。
391 0
|
缓存 前端开发 Java
|
XML Android开发 数据格式
动画必须有(一): 属性动画浅谈
目录 前言 ObjectAnimator的初步使用 用AnimatorSet进行动画混合 将动画写在xml中 动画监听 ViewPropertyAnimator上手 最后 前言 官方文档传送门 属性动画是非常非常好用的, 谷歌自己都说这是一个强大的框架.
1254 0
|
前端开发 Android开发
01.自定义View(ArcView弧形进度条)
开始重新学习一下自定义View的相关知识,借鉴了一些网上的文章,目前在跟这位博主学习,大家可以关注一下 作者:红橙Darren 链接:https://www.
1132 0