您的位置:首页 > 其它

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

2016-07-07 16:20 447 查看
先看一下效果图:


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

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
{
    CGFloat _touchY;
    CAShapeLayer * _headLayer;
    CGFloat _beganY;

}

- (void)viewDidLoad {
    [super
viewDidLoad];
    
    self.view.backgroundColor = [UIColor
lightGrayColor];
    
    _headLayer = [CAShapeLayer
layer];
    _headLayer.fillColor = [UIColor
whiteColor].CGColor;
    _headLayer.strokeColor = [UIColor
clearColor].CGColor;
    _headLayer.frame =
CGRectMake(0,
0, CGRectGetWidth(self.view.frame),
150);
    [self.view.layer
addSublayer:_headLayer];
}

- (void)didReceiveMemoryWarning {
    [super
didReceiveMemoryWarning];

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent
*)event{
    CGPoint point = [[touches
anyObject] locationInView:self.view];
    _beganY = point.y;
}

- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent
*)event{
    CGPoint point = [[touches
anyObject] locationInView:self.view];
    _touchY = (point.y -
_beganY) > 150?150:(point.y -
_beganY);
    
    UIBezierPath * path = [UIBezierPath
bezierPath];
    [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滑动的代理方法中,拿到对应的坐标就可以了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: