2.1 HandleImageView-接收图片,并进行手势识别处理
HandleImageView.h
#import <UIKit/UIKit.h>
typedef void(^HandleImageViewBlock) (UIImage *image);
@interface HandleImageView : UIView
@property (nonatomic,strong) UIImage *image;
@property (nonatomic,copy) HandleImageViewBlock block;
@end
HandleImageView.m
#import “HandleImageView.h”
#import “UIImage+Tool.h”
@interface HandleImageView()
@property (nonatomic,weak) UIImageView *imageView;
@end
@implementation HandleImageView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
//添加UIImageView
[self addImageView];
//添加手势
[self addGestureRecognizers];
}
return self;
}
-(void)addGestureRecognizers
{
//1.长按
UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
[_imageView addGestureRecognizer:longPress];
[self addPinch];
[self addRotation];
}
//长按方法
-(void)longPress:(UILongPressGestureRecognizer *)longPress
{
if(longPress.state==UIGestureRecognizerStateEnded)
{
[UIView animateWithDuration:0.5 animations:^{
_imageView.alpha=0.3;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.5 animations:^{
_imageView.alpha=1;
} completion:^(BOOL finished) {
//1.截屏
UIImage *newImage=[UIImage imageWithCaptureView:self];
//2.把图片传给控制器
_block(newImage);
//3.把自己移除父控制器
[self removeFromSuperview];
}];
}];
}
}
#pragma mark-捏合
-(void)addPinch
{
UIPinchGestureRecognizer *pinch=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinch:)];
// 设置代理的原因:想要同时支持多个手势
pinch.delegate = self;
[_imageView addGestureRecognizer:pinch];
}
-(void)pinch:(UIPinchGestureRecognizer *)pinch
{
_imageView.transform=CGAffineTransformScale(_imageView.transform, pinch.scale, pinch.scale);
//复位
pinch.scale=1;
}
// Simultaneous:同时
// 默认是不支持多个手势
// 当你使用一个手势的时候就会调用
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
- (void)addRotation
{
// rotation
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotation:)];
rotation.delegate = self;
[_imageView addGestureRecognizer:rotation];
}
- (void)rotation:(UIRotationGestureRecognizer *)rotation
{
// _imagView.transform = CGAffineTransformMakeRotation(rotation.rotation);
_imageView.transform = CGAffineTransformRotate(_imageView.transform, rotation.rotation);
// 复位
rotation.rotation = 0;
}
-(void)setImage:(UIImage *)image
{
_image=image;
_imageView.image=image;
}
-(void)addImageView
{
UIImageView *imageView=[[UIImageView alloc]initWithFrame:self.bounds];
imageView.userInteractionEnabled=YES;
_imageView=imageView;
[self addSubview:imageView];
}
// Only override drawRect: if you perform custom drawing.
学习分享
在当下这个信息共享的时代,很多资源都可以在网络上找到,只取决于你愿不愿意找或是找的方法对不对了
很多朋友不是没有资料,大多都是有几十上百个G,但是杂乱无章,不知道怎么看从哪看起,甚至是看后就忘
如果大家觉得自己在网上找的资料非常杂乱、不成体系的话,我也分享一套给大家,比较系统,我平常自己也会经常研读。
2021最新上万页的大厂面试真题
七大模块学习资料:如NDK模块开发、Android框架体系架构…
只有系统,有方向的学习,才能在段时间内迅速提高自己的技术。
这份体系学习笔记,适应人群:
**第一,**学习知识比较碎片化,没有合理的学习路线与进阶方向。
**第二,**开发几年,不知道如何进阶更进一步,比较迷茫。
**第三,**到了合适的年纪,后续不知道该如何发展,转型管理,还是加强技术研究。
由于文章内容比较多,篇幅不允许,部分未展示内容以截图方式展示 。
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!
的技术。
这份体系学习笔记,适应人群:
**第一,**学习知识比较碎片化,没有合理的学习路线与进阶方向。
**第二,**开发几年,不知道如何进阶更进一步,比较迷茫。
**第三,**到了合适的年纪,后续不知道该如何发展,转型管理,还是加强技术研究。
由于文章内容比较多,篇幅不允许,部分未展示内容以截图方式展示 。
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!