WJ's Den


  • 首页

  • 分类

  • 归档

  • 标签

  • 搜索
close

利用CAShaperLayer绘制气泡

发表于 2016-07-12   |   分类于 iOS   |  

实现机制

在每一View的layer层中有一个mask属性,他就是专门来设置该View的遮罩效果的。该mask本身也是一个layer层。我们只需要生成一个自定义的layer,然后覆盖在需要遮罩的View上面即可。问题就归于如何生成入上图所示的不规则图片的Layer。CAShapeLayer可以根据几个点的依次连线,产生一个闭合空间的layer。

实现方法

实现一个CAShapeLayer的Category。

+ (instancetype)createMaskLayerWithView : (UIView *)view{

       CGFloat viewWidth = CGRectGetWidth(view.frame);
       CGFloat viewHeight = CGRectGetHeight(view.frame);

       CGFloat rightSpace = 10;
       CGFloat topSpace = 10;
       CGFloat radius = 10;

       CGPoint point1 = CGPointMake(0, radius);
       CGPoint point2 = CGPointMake(radius, 0);
       CGPoint point3 = CGPointMake(viewWidth-rightSpace-radius, 0);
       CGPoint point4 = CGPointMake(viewWidth-rightSpace, topSpace);
       CGPoint point5 = CGPointMake(viewWidth, topSpace);
       CGPoint point6 = CGPointMake(viewWidth-rightSpace, topSpace+10);
       CGPoint point7 = CGPointMake(viewWidth-rightSpace, viewHeight-radius);
       CGPoint point8 = CGPointMake(viewWidth-rightSpace-radius, viewHeight);
       CGPoint point9 = CGPointMake(radius, viewHeight);
       CGPoint point10 = CGPointMake(0, viewHeight-radius);

       UIBezierPath *path = [UIBezierPath bezierPath];
       [path moveToPoint:point1];
       [path addArcWithCenter:CGPointMake(radius, radius) radius:radius startAngle:M_PI endAngle:M_PI*1.5 clockwise:YES];
       [path addLineToPoint:point2];
       [path addLineToPoint:point3];
       [path addArcWithCenter:CGPointMake(viewWidth-2*radius, radius) radius:radius startAngle:M_PI*1.5 endAngle:0 clockwise:YES];
       [path addLineToPoint:point4];
       [path addLineToPoint:point5];
       [path addLineToPoint:point6];
       [path addLineToPoint:point7];
       [path addArcWithCenter:CGPointMake(viewWidth-2*radius, viewHeight-radius) radius:radius startAngle:0 endAngle:M_PI*0.5 clockwise:YES];
       [path addLineToPoint:point8];
       [path addLineToPoint:point9];
       [path addArcWithCenter:CGPointMake(radius, viewHeight-radius) radius:radius startAngle:M_PI*0.5 endAngle:M_PI clockwise:YES];
       [path addLineToPoint:point10];
       [path closePath];

       CAShapeLayer *layer = [CAShapeLayer layer];
       layer.path = path.CGPath;

       return layer;
}

       UIView *view = [[UIView alloc] initWithFrame:CGRectMake(40, 50, 200, 40)];
       view.backgroundColor = [UIColor orangeColor];
       CAShapeLayer *layer = [CAShapeLayer createMaskLayerWithView:view];
       view.layer.mask = layer;
       [self.view addSubview:view];

参数说明

center:Specifies the center point of the circle (in the current coordinate system) used to define the arc.

radius:Specifies the radius of the circle used to define the arc.

startAngle: Specifies the starting angle of the arc (measured in radians).

endAngle:Specifies the end angle of the arc (measured in raians).

clockwise:The direction in which to draw the arc.




实现效果如下图:



iOS大文件下载遇上nginx反向代理

发表于 2016-07-08   |   分类于 iOS   |  

内网部署nginx,直接挂上2g多的zip包,iOS下载正常,将zip包挂到公司服务器,下载到49.1%(差不多1.07G)就中断链接,于是就各种猜测原因。

  • 文件下载代码写的有问题?

    NSURLSessionDownload,NSURLConnection,AFN换了个遍都一样,虽然没有找到原因,但是发现NSURLSessionDownload下载时占用内存比NSURLConnection少,机制更优。

  • 服务器的问题?

    安卓可以正常下载,windows浏览器可以正常下载,safari下载到49.1%同样网络中断?what?开始抓包,发现没有异常,只有nginx版本不一样,后来发现公司服务器用了反向代理。

    google后尝试写改配置nginx.conf,关闭buffer,proxy_buffering off,可以正常下载了。再尝试开启buffer,然后配置相关参数,也能正常下载,下载的速度和配置的参数有关系,配置参考如下:

    proxy_cache参数配置文件/usr/local/nginx/conf/proxy.conf
    
    proxy_temp_path /home/proxy_temp_dir; 
    proxy_cache_path /home/proxy_cache_dir levels=1:2 keys_zone=cache_one:500m inactive=1d max_size=30g; 
    client_body_buffer_size 512k; 
    proxy_connect_timeout 60; 
    proxy_read_timeout 60; 
    proxy_send_timeout 60; 
    proxy_buffer_size 32k; 
    proxy_buffers 4 64k; 
    proxy_busy_buffers_size 128k; 
    proxy_temp_file_write_size 128k; 
    proxy_next_upstream error timeout invalid_header http_500 http_503 http_404; 
    proxy_cache cache_one; 
    

至此事情告一段落。

Start NexT

发表于 2016-05-24   |   分类于 NexT   |  

NexT使用文档

如何将文章分类

Hello World

发表于 2016-05-24   |  

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

$ hexo new "My New Post"

More info: Writing

Run server

$ hexo server

More info: Server

Generate static files

$ hexo generate

More info: Generating

Deploy to remote sites

$ hexo deploy

More info: Deployment

123
Paul Ding

Paul Ding

iOS & Python Developer

24 日志
8 分类
19 标签
github zhihu
© 2017 Paul Ding
由 Hexo 强力驱动
主题 - NexT.Mist