zoukankan      html  css  js  c++  java
  • 截屏

    #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
    

      

  • 相关阅读:
    搜索优化
    ETL(Extract-Transform-Load的缩写,即数据抽取、转换、装载的过程)
    Tomcat7.0.22在Windows下详细配置过程
    maven 安装配置
    Venus wiki
    搜索引擎基本原理及实现技术——用户查询意图分析
    sql 表自连接
    select 多表查询
    select 嵌套
    Ioc和Aop扩展--多种方式实现依赖注入(构造注入,p命名空间注入,集合类型注入,注入null和注入空值)
  • 原文地址:https://www.cnblogs.com/yedayi/p/5140598.html
Copyright © 2011-2022 走看看