果冻效果

果冻效果

 

说明

参考源码 https://github.com/Resory/RYCuteView

 

效果

 

源码

https://github.com/YouXianMing/Animations

//
//  SpringEffectController.m
//  Animations
//
//  Created by YouXianMing on 16/1/17.
//  Copyright  2016年 YouXianMing. All rights reserved.
//

#import "SpringEffectController.h"
#import "WxHxD.h"
#import "UIView+SetRect.h"

@interface SpringEffectController (){

    CGPoint  _centerPoint;
}

@property (nonatomic, strong) UIView         *pointView;
@property (nonatomic, strong) CAShapeLayer   *shapeLayer;
@property (nonatomic, strong) CADisplayLink  *displayLink;

@end

@implementation SpringEffectController

- (void)setup {

    [super setup];

    _centerPoint = self.contentView.center;

    self.shapeLayer           = [CAShapeLayer layer];
    self.shapeLayer.frame     = self.contentView.bounds;
    self.shapeLayer.fillColor = [UIColor redColor].CGColor;
    self.shapeLayer.path      = [self calculatePathWithPoint:CGPointMake(Width / 2.f, Height / 2.f)].CGPath;
    [self.contentView.layer addSublayer:self.shapeLayer];

    self.pointView                   = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 4, 4)];
    self.pointView.center            = self.contentView.center;
    [self.contentView addSubview:self.pointView];

    self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkEvent)];
    [self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

    UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureEvent:)];
    [self.contentView addGestureRecognizer:panGesture];

}

- (UIBezierPath *)calculatePathWithPoint:(CGPoint)point {

    UIBezierPath *path = [UIBezierPath bezierPath];

    [path moveToPoint:CGPointMake(0, Height / 2.f)];
    [path addLineToPoint:CGPointMake(0, Height)];
    [path addLineToPoint:CGPointMake(Width, Height)];
    [path addLineToPoint:CGPointMake(Width, Height / 2.f)];
    [path addQuadCurveToPoint:CGPointMake(0, Height / 2.f)
                 controlPoint:point];

    return path;
}

- (void)panGestureEvent:(UIPanGestureRecognizer *)panGesture {

    CGPoint point          = [panGesture locationInView:panGesture.view];
    CGPoint calculatePoint = CGPointMake((point.x + _centerPoint.x) / 2.f, (point.y + _centerPoint.y) / 2.f);

    if (panGesture.state == UIGestureRecognizerStateChanged) {

        self.shapeLayer.path  = [self calculatePathWithPoint:calculatePoint].CGPath;
        self.pointView.center = calculatePoint;

    } else if (panGesture.state == UIGestureRecognizerStateCancelled ||
               panGesture.state == UIGestureRecognizerStateEnded ||
               panGesture.state == UIGestureRecognizerStateFailed) {

        [UIView animateWithDuration:1.0 delay:0.0 usingSpringWithDamping:0.25f initialSpringVelocity:0
                            options:UIViewAnimationOptionCurveEaseInOut
                         animations:^{

                             self.pointView.center = self.contentView.center;

                         } completion:nil];
    }
}

- (void)displayLinkEvent {

    CALayer *layer       = self.pointView.layer.presentationLayer;
    self.shapeLayer.path = [self calculatePathWithPoint:layer.position].CGPath;
}

@end
时间: 2024-07-28 14:11:11

果冻效果的相关文章

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

项目中在Tabbar中间的按钮要从底部弹出视图并有果冻效果,在CocoaChina中找了一篇博客用 UIBezierPath 实现果冻效果,github,自己就按着上面的demo修改了一下( 之前也是想着自己一行一行动手敲代码,小伙伴总是说我不要重复造轮子),也正好通过这个学习一下CADisplayLink. CADisplayLink是一个能让我们以和屏幕刷新率相同的频率将内容画到屏幕上的定时器.我们在应用中创建一个新的 CADisplayLink 对象,把它添加到一个runloop中,并给它

Android实现果冻滑动效果的控件_Android

前言 在微信是的处理方法是让用户滑动,但最终还是回滚到最初的地方,这样的效果很生动(毕竟成功还是取决于细节).那么在安卓我们要怎么弄呢.下面为大家介绍一下JellyScrollView,是我继承ScrollView的一个有阻尼的效果的果冻滑动控件. 下面话不多说了,先来看看效果图 (在虚拟机或者真机跑起来是很流畅,可能是录制视频做成gif的时候有点卡顿.) 实现原理 其实只需要重写下它的拦截方法的逻辑就好了,ScrollView的拦截方法onInterceptTouchEvent一般情况下都默认

疯狂流行的动效!究竟是交互设计还是视觉设计?

  @可风f (金山网络交互设计师):自从iOS7发布后UI圈就开始疯狂流行起动画效果,尤其是在Facebook Home之后,大家觉得如果没有酷炫转场.扭来扭去元素,产品就好像上个世纪的老古董一样.但是让整个圈子争相学习的风尚背后却还仍然有一个争议:动效是交互设计还是视觉设计? 在很多外行人眼中,看到一个App动画不错,往往脱口而出的是"哇,这个App交互好棒!".或者老板觉得产品太死板了,会对着大家说"我们的产品交互还需要再打磨一下".其实从严格意义上来说,动效

CODE大全大量Flash网站收藏

我的博客:CODE大全:www.codedq.net:业余草:www.xttblog.com:爱分享:www.ndislwf.com或ifxvn.com. http://www.wallop.com在线flash社区,个人空间. http://www.doof.com/doof/在线flash社区,很强,界面也很棒 http://Maps.amung.usflash网站来客定位. ttp://www.splashup.com/splashup/杀了我吧,这都做出来,在线photoshop,fle

史上最全的iOS开源项目分类汇总

楼主转载的,并未亲自测试 Category/Util  sstoolkit 一套Category类型的库,附带很多自定义控件 功能不错-        BFKit 又一套Category类型的 Kit,还有几个工具类        APUtils 又一套Category类型的 Kit        QSKit 又一套Category类型的 Kit        iOS-Categories 又一套Category类型的 Kit        BlocksKit 将Block风格带入UIKit和F

如何用ubuntu LiveCD测试台式电脑或笔记本电脑

测试目的: 1.核对电脑的配置,以免被奸商骗了.可能现在随着大家电脑知识的普遍提高,敢堂而皇之用赛扬冒充奔腾的并不多了,但还是小心为好. 2.测试电脑的硬件和硬件对linux的兼容性,如果你打算买后装linux的话,这点尤为重要. ubuntu Desktop LiveCD的获得: 方法1.从 http://www.ubuntu.com/getubuntu/download 下载,然后自己刻录.不推荐用 alertnate CD. 方法2.到 https://shipit.ubuntu.com/

用ubuntu LiveCD测试台式电脑硬件兼容性

本文介绍了到电脑城买电脑的时候,付钱之前,如何用ubuntu LiveCD测试台式电脑,本本或本本样机的方法. 建议直接把本页面保存到u盘中,到电脑城试机时,命令可以直接拷贝粘贴 Larry.N.J.http://www.aliyun.com/zixun/aggregation/16528.html">Ellison 写道: The most important thing in choosing a machine on whichto learn/use Linux is whethe

iOS仿今日头条滑动导航

之前写了篇博客网易首页导航封装类.网易首页导航封装类优化,今天在前两个的基础上仿下今日头条. 1.网易首页导航封装类中主要解决了上面导航的ScrollView和下面的页面的ScrollView联动的问题,以及上面导航栏的偏移量. 2.网易首页导航封装类优化中主要解决iOS7以上滑动返回功能中UIScreenEdgePanGestureRecognizer与ScrollView的滑动的手势冲突问题. 今天仿今日头条滑动导航和网易首页导航封装类优化相似,这个也是解决手势冲突,UIPanGesture

Swift版使用ThPullRefresh实现下拉上拉刷新数据_Swift

最近自己写了一个下拉加载最新,上拉加载更多的刷新控件.借鉴了其他优秀开源代码的实现效果比如MJRefresh和DGElasticPullRefresh.主要是为了学习别人的优秀思想. 如何使用: Cocoapods 导入:pod 'ThPullRefresh', 在项目中 import 'ThPullRefresh' 手动导入:将'ThPullRefresh' 文件夹中的所有文件拽入项目中   head与foot基本效果的添加 具体代码如下: override func viewDidLoad(