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 ...
随机推荐
- Crowdsourcing(众包)
群众外包(英语:crowdsourcing)是互联网带来的新的生产组织形式.<连线>(Wired)杂志记者Jeff Howe于2006年发明的一个专业术语,用来描述一种新的商业模式,即企业 ...
- TRUNK的作用功能.什么是TRUNK
TRUNK的作用功能.什么是TRUNK(转) [复制链接] 发表于 2011-11-24 11:01 | 来自 51CTO网页 在技术领域中把TRUNK翻译为中文是“主干.干线.中继线.长途线 ...
- Spring学习进阶 (三) Spring AOP
一.是什么AOP是Aspect Oriented Programing的简称,最初被译为“面向方面编程”:AOP通过横向抽取机制为无法通过纵向继承体系进行抽象的重复性代码提供了解决方案.比如事务的控制 ...
- [weird problem] the xm file transfered by wcf,some sections in it were always repeated
some sections in xml are always repeated,I received these file by wcf. I thought it's caused by buff ...
- Android 全屏显示的方法(不包含状态栏)
我们都知道在Android中某些功能的实现往往有两种方法:一种是在xml文件中设置相应属性,另一种是用代码实现.同样Android实现全屏显示也可以通过这两种方法实现: 1.在AndroidManif ...
- 收藏Javascript中常用的55个经典技巧
1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键 <table border oncontextmenu ...
- [转]Mybatis3.x与Spring4.x整合
原文地址:http://www.cnblogs.com/xdp-gacl/p/4271627.html 一.搭建开发环境 1.1.使用Maven创建Web项目 执行如下命令: mvn archetyp ...
- ( 转 ) Android自绘字体大小paint.settextsize随分辨率大小变化
1.获取当前设备的屏幕大小 DisplayMetrics displayMetrics = new DisplayMetrics(); this.getWindowManager().getDefau ...
- iOS开发小技巧--图片的圆角处理
图片圆角处理方案一: 缺点是图片多了感觉卡 设置图层的CornerRadius属性 -- 设置了圆角后,运行程序没有反应,多半是没有设置下面这句:让内容遵循设置的边缘 masksToBounds = ...
- react 属性与状态 学习笔记
知识点:1.react 属性的调用 this.props.被调用的属性名 设置属性的常用方法:var props = { one: '123', two: 321}调用这个属性:<HelloWo ...