iOS画板实现第二波
2016-07-04 09:29
369 查看
画板实现第二波
1.将对图片添加一系列手势操作,原有实现不能实现
以前详细说明个六种手势在控件上的操作(手势只能添加在控件上)
对原有代码进行改造
1.1添加一个图片处理的VIEW
1.2图片view中一些设置
2.添加各种手势
3.对于手势无法响应问题的解决
3.1解决的方法:首先检查这个控件是否能响应事件,如:imageView,还有就是控件的父控件就不能响应
3.2手势里面的写法差不多
4.介绍block的一种用法,用来解决耦合
4.1当操作了手势后,想保存图片到drawView上时
1.self.superView可以获得,再强转,耦合
2.使用block:在ImageHandleView.h中定义,在viewControoler.m中写好要执行的代码(因国在viewControoler中可以获得drawView对象),在图片处理完时执行此block(在imageHandleView.m执行)
代码依从2所说来写(具体代码请看github)
5.源代码详细地址
github
http://git.oschina.net/HYLAppleDream/Quartz2D/tree/master/画板实现(添加各种图片手势操作)/画板实现?dir=1&filepath=画板实现%28添加各种图片手势操作%29%2F画板实现&oid=ce46de00f5bd57c88844dac1fafc46bcc1529d62&sha=8943642ef926ab3073cfe3c907c2b555c1754f1e
1.将对图片添加一系列手势操作,原有实现不能实现
以前详细说明个六种手势在控件上的操作(手势只能添加在控件上)
对原有代码进行改造
1.1添加一个图片处理的VIEW
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{ NSLog(@"%@",info); UIImage *image=info[UIImagePickerControllerOriginalImage]; HYLImageHandleView *imageHandView=[[HYLImageHandleView alloc]initWithFrame:self.drawView.bounds]; [self.drawView addSubview:imageHandView]; imageHandView.imageView.image=image; [self dismissViewControllerAnimated:YES completion:nil]; }
1.2图片view中一些设置
#pragma mark - setter/getter -(UIImageView *) imageView{ if (_imageView==nil) { UIImageView *imageView=[[UIImageView alloc]initWithFrame:self.bounds]; _imageView=imageView; [self addSubview:_imageView]; } return _imageView; } #pragma mark -drawRect - (void)drawRect:(CGRect)rect { }
2.添加各种手势
-(instancetype) initWithFrame:(CGRect)frame{ if (self=[super initWithFrame:frame]) { [self setPan]; [self setLongPress]; [self setRotation]; [self setPinch]; } return self; }
#pragma mark - setpan -(void) setPan{ UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pan:)]; [self.imageView addGestureRecognizer:pan]; } -(void) pan:(UIPanGestureRecognizer *)pan{ } #pragma mark -setLongPress -(void) setLongPress{ UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)]; [self.imageView addGestureRecognizer:longPress]; } -(void) longPress:(UILongPressGestureRecognizer *)longPress{ } #pragma mark - setRotation -(void) setRotation{ UIRotationGestureRecognizer *rotation=[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotation:)]; [self.imageView addGestureRecognizer:rotation]; } -(void) rotation:(UIRotationGestureRecognizer *)rotation{ } #pragma mark -setPinch -(void) setPinch{ UIPinchGestureRecognizer *pinch=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinch:)]; [self.imageView addGestureRecognizer:pinch]; } -(void) pinch:(UIPinchGestureRecognizer *)pinch{ }
3.对于手势无法响应问题的解决
3.1解决的方法:首先检查这个控件是否能响应事件,如:imageView,还有就是控件的父控件就不能响应
-(UIImageView *) imageView{ if (_imageView==nil) { UIImageView *imageView=[[UIImageView alloc]initWithFrame:self.bounds]; _imageView=imageView; //注意点,允许用户交互,不能响应事件时一般查这个 _imageView.userInteractionEnabled=YES; self.backgroundColor=[UIColor clearColor]; [self setPan]; [self setLongPress]; [self setRotation]; [self setPinch]; [self addSubview:_imageView]; } return _imageView; }
3.2手势里面的写法差不多
4.介绍block的一种用法,用来解决耦合
4.1当操作了手势后,想保存图片到drawView上时
1.self.superView可以获得,再强转,耦合
2.使用block:在ImageHandleView.h中定义,在viewControoler.m中写好要执行的代码(因国在viewControoler中可以获得drawView对象),在图片处理完时执行此block(在imageHandleView.m执行)
代码依从2所说来写(具体代码请看github)
/** imageHandleCompletionBlock*/ @property (nonatomic,strong) void (^imageHandleCompletionBlock)(UIImage *image);
//保存一份代码,当图片处理完时调用; imageHandView.imageHandleCompletionBlock=^(UIImage *image){ self.drawView.image=image; };
// self.imageView.image=image; //重画drawView,执行block if (self.imageHandleCompletionBlock) { self.imageHandleCompletionBlock(image); }
5.源代码详细地址
github
http://git.oschina.net/HYLAppleDream/Quartz2D/tree/master/画板实现(添加各种图片手势操作)/画板实现?dir=1&filepath=画板实现%28添加各种图片手势操作%29%2F画板实现&oid=ce46de00f5bd57c88844dac1fafc46bcc1529d62&sha=8943642ef926ab3073cfe3c907c2b555c1754f1e
相关文章推荐
- iOS画板实现第二波
- 【代码笔记】iOS-先选择城市,然后,跳转Tabbar
- 【代码笔记】iOS-先选择城市,然后,跳转Tabbar
- iOS禁用部分文件ARC
- IOS人脸识别
- iOS滚珠菜单动效
- iOS-FMDB
- iOS-使用CFStringTransform将汉字转换为拼音
- iOS学习- 24 Core Data by Tutorials - CH04
- iOS 引导页
- iOS10开发
- 漫谈安卓和ios,mac os x
- 记录一下iOS开发中琐碎的点点_4
- iOS图层layer操作
- iOS中表单视图第三方控件——FXForms
- iOS NSURL、NSBundle获取文件,解析文件,存储文件等操作
- iOS中定位以及地图的使用
- Xamarin.iOS开发初体验
- iOS中,ARC的环境下的单例模式。