具体使用的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 - 果冻效果的更多相关文章

  1. iOS - 用 UIBezierPath 实现果冻效果

    最近在网上看到一个很酷的下拉刷新效果(http://iostuts.io/2015/10/17/elastic-bounce-using-uibezierpath-and-pan-gesture/). ...

  2. iOS开发——图形编程OC篇&粘性动画以及果冻效果

    粘性动画以及果冻效果 在最近做个一个自定义PageControl——KYAnimatedPageControl中,我实现了CALayer的形变动画以及CALayer的弹性动画,效果先过目: 先做个提纲 ...

  3. 谈谈iOS中粘性动画以及果冻效果的实现

    在最近做个一个自定义PageControl——KYAnimatedPageControl中,我实现了CALayer的形变动画以及CALayer的弹性动画,效果先过目: https://github.c ...

  4. 转:谈谈iOS中粘性动画以及果冻效果的实现

    在最近做个一个自定义PageControl——KYAnimatedPageControl中,我实现了CALayer的形变动画以及CALayer的弹性动画,效果先过目: 先做个提纲: 第一个分享的主题是 ...

  5. CADisplayLink+弹簧动画实现果冻效果

    项目中在Tabbar中间的按钮要从底部弹出视图并有果冻效果,在CocoaChina中找了一篇博客用 UIBezierPath 实现果冻效果,github,自己就按着上面的demo修改了一下( 之前也是 ...

  6. 【转】提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果

    原文网址:http://www.zhimengzhe.com/IOSkaifa/37910.html MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单.方便,并且可以对显 ...

  7. Android仿IOS回弹效果 ScrollView回弹 总结

    Android仿IOS回弹效果  ScrollView回弹 总结 应项目中的需求  须要仿IOS 下拉回弹的效果 , 我在网上搜了非常多 大多数都是拿scrollview 改吧改吧 试了一些  发现总 ...

  8. Android 实现高仿iOS桌面效果之可拖动的GridView(上)

    转载请标明出处:http://blog.csdn.net/sk719887916/article/details/40074663,作者:skay      最近项目中遇到一个LIstview的拖动效 ...

  9. iOS 波浪效果的实现

    iOS 波浪效果的实现 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #4f8187; background-c ...

随机推荐

  1. .net程序员转行做手游开发经历(五)

    大家好,真的是好长时间都没有更新博客了.上来博客园发现很多朋友还在关注我们,那给大家汇报下最近的一些进展. 收费版上线了,但是下载量不是很多,刚发布的时候下载每天的下载还是挺多,我们几个小伙伴在论坛. ...

  2. hystrix-turbine 监控的使用

    1.   概述 Demo地址:http://git.oschina.net/zhou666/spring-cloud-7simple/tree/master/cloud-hystrix-turbine ...

  3. isinstance

    class Foo: pass obj = Foo() isinstance(obj,Foo) class Foo: pass obj = Foo() isinstance(obj ,Foo) pri ...

  4. js和jQuery的日常

    让当前页面显示整个屏幕 - (iframe 从后台跳转到前台的时候容易多层嵌套)$(document).ready(function(){ if(window.top != window.self) ...

  5. jenkins 把包传到远程服务器上

    首先我们在 一台服务器上部署svn,maven,jdk,tomcat,nexus,还有Jenkins. 这里我主要记录Jenkins. 首先我们从网上下载Jenkins的包 wget http://m ...

  6. python 批量更改文件名

    工作中遇到一种情况,就是市场部那边经常发过来一些apk的包 但是要求更改名字,文件太多了,没办法,只有想办法了,还好命名都是有规则的 比如说 YZLoan-gdtyyb-V2.23.apk------ ...

  7. 用ElasticSearch和Protovis实现数据可视化

    搜索引擎最重要的目的,嗯,不出意料就是搜索.你传给它一个请求,然后它依照相关性返回你一串匹配的结果.我们可以根据自己的内容创造各种请求结构,试验各种不同的分析器,搜索引擎都会努力尝试提供最好的结果. ...

  8. 在Windows .NET平台下使用Memcached

    网上关于Memcached的文章很多,但据我观察,大多是互相转载或者抄袭的,千篇一律.有些则是直接整理的一些超链接然后贴出来.那些超链接笔者大概都进去看了,其实关于Memcached的中文的技术文章, ...

  9. 通过javascript在网页端生成zip压缩包并下载

    zip.js是什么 zip.js的github项目地址:http://gildas-lormeau.github.io/zip.js/ 通过zip.js封装一个能在网页端生成zip文件的插件, 直接在 ...

  10. 状态压缩 poj 3254

    n * m 个玉米 n*m个数字 0 或者1 1可以种玉米 0 不能  种玉米不能相邻 计算有几种 种的方法 #include<stdio.h> #include<algorithm ...