• 截屏


    #import "ViewController.h"
    
    @interface ViewController ()
    
    @property (nonatomic, weak) UIView *cover;
    
    @property (nonatomic, assign) CGPoint oriP;
    
    @property (weak, nonatomic) IBOutlet UIImageView *imageView;
    @property (weak, nonatomic) IBOutlet UIView *view1;
    
    @end
    
    @implementation ViewController
    //- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    //{
    //    CGRect frame = _view1.frame;
    ////    frame.size.width = -100;
    ////    _view1.frame = frame;
    ////}
    - (UIView *)cover
    {
        if (_cover == nil) {
            UIView *view = [[UIView alloc] init];
            
            
            view.backgroundColor = [UIColor blackColor];
            view.alpha = 0.5;
            
            _cover = view;
            
            [self.view addSubview:view];
            
        }
        return _cover;
    }
    
    - (IBAction)pan:(UIPanGestureRecognizer *)sender {
        // 获取下当前的触摸
        CGPoint curP = [sender locationInView:_imageView];
        if (sender.state == UIGestureRecognizerStateBegan) {
            // 记录下一开始的位置
            _oriP = curP;
        }
        
        // 计算下黑色蒙版的frame
        CGFloat w = curP.x - _oriP.x;
        CGFloat h = curP.y - _oriP.y;
        
        self.cover.frame = CGRectMake(_oriP.x, _oriP.y, w, h);
    
        
        if (sender.state == UIGestureRecognizerStateEnded) { // 手指抬起
            
            // 裁剪图片,生成一张新图片
            
            // 开启位图上下文
            UIGraphicsBeginImageContextWithOptions(_imageView.bounds.size, NO, 0);
            
            // 设置裁剪区域
            UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.cover.frame];
            [path addClip];
            
            
            // 绘制图片
            [_imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
            
            // 生成图片
            UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
            
            // 关闭上下文
            UIGraphicsEndImageContext();
            
            _imageView.image = image;
            
            [self.cover removeFromSuperview];
            
            
        }
        
        
    }
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        
        // 创建拖动手势
    //    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
    //    
    //    [_imageView addGestureRecognizer:pan];
    }
    
    //- (void)pan:(UIPanGestureRecognizer *)pan
    //{
    //    NSLog(@"%s",__func__);
    //}
    
    
    @end
    

      

  • 相关阅读:
    桥接模式新解:客户端服务器模式
    laravel-admin 自定义导出表单
    PHP实现git部署的方法,可以学学!
    PHP的安全性问题,你能说得上几个?
    nginx的四个基本功能
    laravel orm
    laravel-admin列表排序在使用了$grid->model()->latest()后$grid其它加上sortable()可排序的列在排序时不起作用
    Laravel 5.4: 特殊字段太长报错 420000 字段太长
    关于在phpStudy环境下,windows cmd中 php不是内部命令问题
    phpstudy安装好之后mysql无法启动(亲测可行)
  • 原文地址:https://www.cnblogs.com/yedayi/p/5140598.html
Copyright © 2020-2023  润新知