截屏
2016-01-18 21:45
429 查看
#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
相关文章推荐
- 【BZOJ1468】Tree
- 总是提示下载百度云管家的解决办法
- STL_算法_删除(unique、unique_copy)
- clover 显卡注入功能详细讲解
- layoutinflaterde 使用
- 安卓设置imageview变暗的效果,类似于qq离线状态
- cacti常见问题
- Android 内核之Android与Linux的关系
- Numpy的tile函数
- Spfa 模板
- 瀑布式开发、迭代开发、敏捷开发、XP与SCRUM的区别
- 【BZOJ2152】聪聪可可
- VS2010使用NuGet程序包管理器
- Java基础-实现文件搜索功能
- Java基础-实现文件搜索功能
- sublime插件安装
- 谷歌软件测试之道
- Linux学习之more命令
- python之路(五)-文件操作
- Divide and conquer:Median(POJ 3579)