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 ...
随机推荐
- 安装.NET Framework后程序无法启动的错误处理
最近发现一直在使用的Database.NET软件无法正常使用了,表现为当尝试进行Sql Server的连接创建时,直接报错 在事件查看器具体错误信息为: 日志名称: Applicat ...
- NPOI2.0学习(二)
如果你要编辑的行和单元格,原本没有值,或者从未创建过的,就必须先创建. //在第二行创建行 IRow row = sheet.CreateRow(); //在第二行的第一列创建单元格 ICell ce ...
- hiho一下 第六十六周
题目链接:这是一道水爆了的广搜题 #include<iostream> #include<stdio.h> #include<algorithm> #include ...
- 屠龙之路_向恶龙Alpha进发_FirstDay
听说山的那边海的那边,出现了一头名为Alpha的恶龙,此龙无恶不作,还掠走了国王那漂酿的公主.少年很是气愤,大吼:"放开那女孩!!!",于是找到了志同道合的六位勇士,一起组成了屠龙 ...
- Beta版本冲刺Day4
会议讨论: 628:由于昨天的考试我们组目前只把项目放到了服务器上,配置Java环境遇到了问题.601:将一些原来的界面进行了修改,修改成了更加美观的外形. 528:进行一些还未完成得到功能,比如查询 ...
- MySQL Workbench使用及教程
MySQL Workbench是一款专为MySQL设计的ER/数据库建模工具.它是著名的数据库设计工具DBDesigner4的继任者.你可以用MySQL Workbench设计和创建新的数据库图示,建 ...
- JS实时定位
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- 用 Fabric 实现自动化部署
自动化部署代码 http://liyangliang.me/posts/2015/06/deploy-applications-using-fabric/ http://fabric-docs-cn. ...
- Android自定义PopupWindow显示在控件上方或者下方
记录学习之用 View view = mInflater.inflate(R.layout.layout_popupwindow, null); PopUpwindowLayout popUpwind ...
- Elasticsearch 1.X 版本Java插件开发
接上一篇<Elasticsearch 2.X 版本Java插件开发简述> 开发1.X版本elasticsearch java插件与2.X版本有一些不同,同时在安装部署上也有些不同,主要区别 ...