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 ...
随机推荐
- 理解Android安全机制
本文从Android系统架构着手,分析Android的安全机制以SE Android,最后给出一些Android安全现状和常见的安全解决方案. 1.Android系统架构 Android采用分层的系统 ...
- NetworkSocket结构图
分层思想 NetworkSocket使用分层的思想,分基础层和上层: 1.基础层提供基础通讯,重要的对象有SessionBase.TcpServerBase和TcpClientBase: 2.上层实现 ...
- 关于Task的线程窃取
示例代码: static void Main(string[] args) { ThreadPool.SetMaxThreads(, ); object locker = new object(); ...
- 没有jquery的时候,你看看这个
vjs var br = (function() { var ua = navigator.userAgent.toLowerCase(); browser = { iPhone: /iphone/. ...
- [转]Windows系统注册表知识完全揭密
来源:http://www.jb51.net/article/3328.htm Windows注册表是帮助Windows控制硬件.软件.用户环境和Windows界面的一套数据文件,注册表包含在Wind ...
- HIbernate的对象状态
*临时状态对象: session中没有缓存,且在数据库中没有对应数据. User user1=new User(null,"c50",18); *持久化状态对象: session中 ...
- jq实现登陆页面的拖拽功能
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <script src ...
- 开发错误记录10: Butterknife8.1.0 提示NullPointerException空指针
Butterknife 8.0以后的版本在引入到项目中有变动,按之前的引入方式之后, 会报 空指针! 正确的引入方法是:(在官方的文件上有说明的,记录是为了方便下次引入,直接复制到项目) 在项目的.g ...
- 手把手windows64位配置安装python2.7
这几天公司要用到python的一些算法,让我调研一番,之前对Python一次没接触的我在安装配置环境的时候由于版本的问题,折腾了好久,这里简单介绍一下我的安装方法,需要安装pyhton的朋友可以不再向 ...
- Qt学习中遇到的问题
问题: 一个Qt小项目,编译成功并成功运行,但应用程序输出中出现如下异常:FTH: (9892): *** Fault tolerant heap shim applied to current pr ...