iOS - 果冻效果
具体使用的CADisplayLink和贝塞尔曲线
下载地址:https://github.com/nLoser/CustomAnimation
效果:

//
// DisplayView.m
// CustomAnimation
//
// Created by LV on 16/1/6.
// Copyright © 2016年 Wieye. All rights reserved.
//
#import "DisplayView.h"
@interface DisplayView ()
@property (nonatomic, strong) CADisplayLink * displayLink;
@property (nonatomic, assign) CGFloat to;
@property (nonatomic, assign) CGFloat from;
@end
@implementation DisplayView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
NSLog(@"Init");
self.backgroundColor = [UIColor clearColor];
}
return self;
}
- (void)drawRect:(CGRect)rect
{
NSLog(@"DrawRect");
[[UIColor purpleColor] setFill];
CALayer *layer = self.layer.presentationLayer;
CGFloat progress = - (layer.position.y - self.to) / (self.from - self.to);
CGFloat height = CGRectGetHeight(rect);
CGFloat deltaHeight = height / * (0.5 - fabs(progress - 0.5));
CGPoint topLeft = CGPointMake(, deltaHeight);
CGPoint topRight = CGPointMake(CGRectGetWidth(rect), deltaHeight);
CGPoint bottomLeft = CGPointMake(, height);
CGPoint bottomRight = CGPointMake(CGRectGetWidth(rect), height);
UIBezierPath* path = [UIBezierPath bezierPath];
[path moveToPoint:topLeft];
[path addQuadCurveToPoint:topRight controlPoint:CGPointMake(CGRectGetMidX(rect), )];
[path addLineToPoint:bottomRight];
[path addQuadCurveToPoint:bottomLeft controlPoint:CGPointMake(CGRectGetMidX(rect), height - deltaHeight)];
[path closePath];
[path fill];
}
#pragma mark - Public Action
- (void)startAnimationFrom:(CGFloat)from to:(CGFloat)to
{
if (self.displayLink == nil)
{
NSLog(@"StartAnimation");
self.from = from;
self.to = to;
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(tick:)];
[self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}
[UIView animateWithDuration: delay: usingSpringWithDamping: options: animations:^{
self.center = CGPointMake(self.center.x, self.to);
} completion:^(BOOL finished)
{
[self stopAnimation];
}];
}
- (void)stopAnimation
{
if (self.displayLink != nil)
{
[self.displayLink invalidate];
self.displayLink = nil;
}
}
#pragma mark - Private Action
- (void)tick:(CADisplayLink *)displayLink
{
[self setNeedsDisplay];
}
@end
#import <UIKit/UIKit.h> @interface DisplayView : UIView - (void)startAnimationFrom:(CGFloat)from to:(CGFloat)to; - (void)stopAnimation; @end
iOS - 果冻效果的更多相关文章
- iOS - 用 UIBezierPath 实现果冻效果
最近在网上看到一个很酷的下拉刷新效果(http://iostuts.io/2015/10/17/elastic-bounce-using-uibezierpath-and-pan-gesture/). ...
- iOS开发——图形编程OC篇&粘性动画以及果冻效果
粘性动画以及果冻效果 在最近做个一个自定义PageControl——KYAnimatedPageControl中,我实现了CALayer的形变动画以及CALayer的弹性动画,效果先过目: 先做个提纲 ...
- 谈谈iOS中粘性动画以及果冻效果的实现
在最近做个一个自定义PageControl——KYAnimatedPageControl中,我实现了CALayer的形变动画以及CALayer的弹性动画,效果先过目: https://github.c ...
- 转:谈谈iOS中粘性动画以及果冻效果的实现
在最近做个一个自定义PageControl——KYAnimatedPageControl中,我实现了CALayer的形变动画以及CALayer的弹性动画,效果先过目: 先做个提纲: 第一个分享的主题是 ...
- CADisplayLink+弹簧动画实现果冻效果
项目中在Tabbar中间的按钮要从底部弹出视图并有果冻效果,在CocoaChina中找了一篇博客用 UIBezierPath 实现果冻效果,github,自己就按着上面的demo修改了一下( 之前也是 ...
- 【转】提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果
原文网址:http://www.zhimengzhe.com/IOSkaifa/37910.html MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单.方便,并且可以对显 ...
- Android仿IOS回弹效果 ScrollView回弹 总结
Android仿IOS回弹效果 ScrollView回弹 总结 应项目中的需求 须要仿IOS 下拉回弹的效果 , 我在网上搜了非常多 大多数都是拿scrollview 改吧改吧 试了一些 发现总 ...
- Android 实现高仿iOS桌面效果之可拖动的GridView(上)
转载请标明出处:http://blog.csdn.net/sk719887916/article/details/40074663,作者:skay 最近项目中遇到一个LIstview的拖动效 ...
- iOS 波浪效果的实现
iOS 波浪效果的实现 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #4f8187; background-c ...
随机推荐
- echarts .NET类库开源
前言: 2012年从长沙跑到深圳,2016年又从深圳回到长沙,兜兜转转一圈,又回到了原点.4年在深圳就呆了一家公司,回长沙也是因为深圳公司无力为继,长沙股东老板挽留,想想自己年纪也不小了.就回来了,在 ...
- WebService的两种方式SOAP和REST比较 (转)
我的读后感:由于第一次接触WebService,对于很多概念不太理解,尤其是看到各个OpenAPI的不同提供方式时,更加疑惑.如google map api采用了AJAX方式,通过javascript ...
- JavaScript面试题收集(一)
简述javascript中的“=.==.===”的区别? 答:=赋值 ==比较是否一般相等 "3"==3 //会做类型的隐式转换,true ===比较是否严格相等 " ...
- 37-more 简明笔记
分页显示文本 more [options] file more用于分页显示文本文件,最早出现在BSD当中,但这一命令非常基本,后来less命令对其做了增强,所谓的less也就是少即是多 参数 file ...
- Linux服务器配置git服务
前言 Git是一个非常著名的分布式版本控制系统,而广大开发者更是习惯在最大的远程仓库GitHub上提交自己的代码.但是有时候,一些小项目不值得放到GitHub上去,或是由于隐私问题不好在GitHub的 ...
- 我的第一个jsp程序-实现注册登录留言功能
1,注册功能,包括两个页面 zhuce.jsp注册页面 <%@ page language="java" contentType="text/html; chars ...
- 【POJ 1743】Musical Theme
后缀数组求了height,模板题啦啦啦 #include<cstdio> #include<cstring> #include<algorithm> using n ...
- poj3694 缩点边双连通分量
Network Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 8669 Accepted: 3175 Descripti ...
- poj1144 求不同割点的个数
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11914 Accepted: 5519 Descript ...
- Maven-常用命令
mvn archetype:create :创建 Maven 项目 mvn compile :编译源代码 mvn deploy 发布项目 mvn test-compile :编译测试代码 mvn te ...