iOS画板实现第二波
2016-07-04 00:00
423 查看
摘要: iOS画板实现第二波
#####画板实现第二波
#####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图层layer操作
- iOS中表单视图第三方控件——FXForms
- iOS NSURL、NSBundle获取文件,解析文件,存储文件等操作
- iOS中定位以及地图的使用
- Xamarin.iOS开发初体验
- iOS中,ARC的环境下的单例模式。
- 在iOS开发中,需要用到的多线程技术。
- 关于iOS中的手势识别
- iOS开发的22个奇葩技巧
- ios推送相关资料整理
- GCD
- iOS Foundation 基础框架
- 重定向 NSLog 输出到文件
- iOS 开发中的各种证书
- iOS 使用Charts框架 折线,柱状,K线,饼状,雷达全攻略
- 欢迎使用CSDN-markdown编辑器
- 如何进入BIOS
- runtime(三)应用 消息转发
- 在FireMonkey iOS应用程序中使用ListBox组件来显示TableView