某些下拉刷新变波浪的效果实现思路

来源:互联网 发布:新能源汽车数据 编辑:程序博客网 时间:2024/05/17 22:01

先看一下效果图:


效果大概就是这样,主要的实现思路其实就是用贝塞尔曲线画那个形状,实现比较简单,但在具体的需要和下拉的时候,需要自行补充细节,代码量比较少,放出代码给大家参考。

#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController

{

    CGFloat _touchY;

    CAShapeLayer * _headLayer;

    CGFloat _beganY;


}



- (void)viewDidLoad {

    [superviewDidLoad];

    

    self.view.backgroundColor = [UIColorlightGrayColor];

    

    _headLayer = [CAShapeLayerlayer];

    _headLayer.fillColor = [UIColorwhiteColor].CGColor;

    _headLayer.strokeColor = [UIColorclearColor].CGColor;

    _headLayer.frame =CGRectMake(0,0, CGRectGetWidth(self.view.frame),150);

    [self.view.layeraddSublayer:_headLayer];

}


- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];


}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    CGPoint point = [[touchesanyObject] locationInView:self.view];

    _beganY = point.y;

}



- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    CGPoint point = [[touchesanyObject] locationInView:self.view];

    _touchY = (point.y -_beganY) > 150?150:(point.y -_beganY);

    

    UIBezierPath * path = [UIBezierPathbezierPath];

    [path moveToPoint:CGPointMake(0,0)];

    [path addLineToPoint:CGPointMake(CGRectGetMaxX(self.view.frame),0)];

    [path addCurveToPoint:CGPointMake(0,0) controlPoint1:CGPointMake(CGRectGetMaxX(self.view.frame),0) controlPoint2:CGPointMake(point.x,_touchY)];

    _headLayer.path = path.CGPath;


}


- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    _headLayer.path =nil;

}


直接复制以上代码粘贴到新建的项目中就可以看到效果了,如果需要应用到tableView的下拉中,则将touchsMove的一系列代码,写到对应的scrollView滑动的代理方法中,拿到对应的坐标就可以了。



0 0
原创粉丝点击