具体使用的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. js下拉框

    Js下拉框   http://sc.chinaz.com/tag_jiaoben/XiaLaKuang.html

  2. NPOI2.0学习(三)

    HSSFWorkbook wk = new HSSFWorkbook();//你用来操作的HSSFWorkbook的实例 ICellStyle cellStyle = wk.CreateCellSty ...

  3. Win2008上.NET4.0部署出错HTTP 错误 500.21 - Internal Server Error的解决方法

    原因:在安装Framework v4.0之后,再启用IIS,导致Framework没有完全安装 解决:开始->所有程序->附件->鼠标右键点击“命令提示符”->以管理员身份运行 ...

  4. IQueryable和list本地集合区别

    详情请看:http://www.cnblogs.com/imust/archive/2012/11/18/2776320.html

  5. Uwp Windows10获取设备位置(经纬度)

    先在Package.appxmanifest中配置位置权限 2. 创建LocationManager类 using System; using System.Collections.Generic; ...

  6. 基于tiny4412原生uboot修改制作SD启动并烧写到emmc

    最近入手tiny4412的标准板,底板SDK型号为1506.但是因为友善之臂提供的superboot不能进入boot菜单,此时我就不能通过tftp下载内核和通过nfs挂载根文件系统,于是想自己做个ub ...

  7. git的配置

    git的配置: Git 提供了一个叫做 git config 的工具,专门用来配置或读取相应的工作环境变量. 这些环境变量,决定了 Git 在各个环节的具体工作方式和行为.这些变量可以存放在以下三个不 ...

  8. canvas拖动

    var canvas=document.getElementById("canvas"); var cxt=canvas.getContext("2d"); v ...

  9. zabbix的配置使用

    1 zabbix忘记密码的解决办法 zabbix的默认密码我们都知道是admin,zabbix都是存在与数据库中的 select * from zabbix.user where alias='adm ...

  10. codeforces Hill Number 数位dp

    http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits:  5000 MS   Memory Limits: ...