• 果冻效果


    果冻效果

    说明

    参考源码 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
  • 相关阅读:
    ios开发-2015-07-28
    ios开发-2015-07-27
    ios开发-2015-07-26
    ios开发-2015-07-25
    ios开发-2015-07-24
    ios开发-2015-07-23
    Selenium学习笔记之010:层级定位 分类: Selenium 2015-07-21 23:17 11人阅读 评论(0) 收藏
    Selenium学习笔记之007:定位一组元素
    Selenium学习笔记之007:定位一组元素 分类: Selenium 2015-07-21 23:03 9人阅读 评论(0) 收藏
    Selenium学习笔记之006:webdriver的八种定位方式 分类: Selenium 2015-07-21 22:33 11人阅读 评论(0) 收藏
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/5137586.html
Copyright © 2020-2023  润新知