果冻效果

简介:

果冻效果

 

说明

参考源码 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


目录
相关文章
|
数据库 存储
典型数据库架构设计与实践 | 架构师之路
本文,将介绍数据库架构设计中的一些基本概念,常见问题以及对应解决方案,为了便于读者理解,将以“用户中心”数据库为例,讲解数据库架构设计的常见玩法。
1295 0
|
9月前
|
移动开发 前端开发 HTML5
【Web端智能聊天客服】之HTML、CSS、Bootstrap的讲解及实例(超详细必看 附源码)
【Web端智能聊天客服】之HTML、CSS、Bootstrap的讲解及实例(超详细必看 附源码)
320 0
|
9月前
|
存储 自然语言处理 关系型数据库
ElasticSearch索引 和MySQL索引那个更高效实用那个更合适
ElasticSearch索引 和MySQL索引那个更高效实用那个更合适
97 0
15道谷歌面试题及答案
关键字:谷歌 Google 面试 保存到相册     第一题:多少只高尔夫球才能填满一辆校车?(职位:产品经理)   解析:通过这道题,谷歌希望测试出求职者是否有能力判断出解决问题的关键。
1804 0
|
9月前
|
Android开发
Android Mediatek USB 核心驱动中增加设备 PID/VID 检查
Android Mediatek USB 核心驱动中增加设备 PID/VID 检查
219 0
|
Web App开发 安全 前端开发
|
6月前
|
安全 网络协议 关系型数据库
firewalld 详细介绍配置(一)
【8月更文挑战第10天】FirewallD是一款动态防火墙管理工具,通过网络区域(zone)定义接口的安全级别。与iptables需重载全部规则相比,FirewallD仅更新变动部分,更高效。它利用iptables作为规则管理入口,自身不具防火墙功能,依赖内核的netfilter实现。区域(zone)代表一组过滤规则,不同区域默认行为各异,如public、work等。服务配置则以人性化名称管理端口,简化规则管理。常用命令包括安装、启动、停止及查询状态等。
95 4
|
6月前
|
消息中间件 缓存 API
RocketMQ - 生产者消息发送流程
RocketMQ - 生产者消息发送流程
105 0

热门文章

最新文章

相关实验场景

更多