某些下拉刷新变波浪的效果实现思路
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滑动的代理方法中,拿到对应的坐标就可以了。
效果大概就是这样,主要的实现思路其实就是用贝塞尔曲线画那个形状,实现比较简单,但在具体的需要和下拉的时候,需要自行补充细节,代码量比较少,放出代码给大家参考。
#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滑动的代理方法中,拿到对应的坐标就可以了。
相关文章推荐
- UVa 437 The Tower of Babylon
- Android Studio、Git 解决合并冲突
- [AWS 入门] CLI
- Android L SurfaceFlinger dump信息全解(一)
- 批量修改|导入Unity3d资源属性,帮助那些遗忘勾、选项的美术同学们 (其实我做美术的时候也一样有健忘症)
- Sphinx 安装,配置,使用,分页
- 1154 能量项链[区间dp]
- WIN32程序挂钩SetLastError,输出错误描述到控制台
- 基于互联网的VOIP电话系统组建
- css3 text-shadow 为网页字体添加阴影
- Linux kernel 关机的底层操作
- CentOS下DB2数据库安装过程详解
- 创建软连接
- Java开发中的23种设计模式详解(二)
- AndroidStudio混淆
- 推荐 张涛 开源实验室
- Java synchronized 关键字的讲解
- Java中System.loadLibrary() 的执行过程
- 创建struts项目
- 设置c#windows服务描述及允许服务与桌面交互的几种方法(作者博客还有一大堆C#创建服务的文章)