1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//
// GoodsImageView.m
// Lighting
//
// Created by 曹云霄 on 16/6/3.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "GoodsImageView.h"
@implementation GoodsImageView
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
UIRotationGestureRecognizer *rotationGes = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(backGroundViewRotationAction:)];
rotationGes.delegate = self;
[self addGestureRecognizer:rotationGes];
UIPinchGestureRecognizer *pinchGes = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(backGroundViewPinchAction:)];
pinchGes.delegate =self;
[self addGestureRecognizer:pinchGes];
UIPanGestureRecognizer *panGes = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(backGroundViewPanAction:)];
[panGes setMinimumNumberOfTouches:1];
[panGes setMaximumNumberOfTouches:1];
panGes.delegate = self;
[self addGestureRecognizer:panGes];
UILongPressGestureRecognizer *longGes = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(LongPressAction:)];
longGes.delegate = self;
[self addGestureRecognizer:longGes];
}
return self;
}
#pragma mark -缩放
-(void)backGroundViewPinchAction:(UIPinchGestureRecognizer *)gesture{
UIView *view = self;
if (gesture.state == UIGestureRecognizerStateBegan || gesture.state == UIGestureRecognizerStateChanged) {
view.transform = CGAffineTransformScale(view.transform, gesture.scale, gesture.scale);
gesture.scale = 1;
}
}
#pragma mark -拖拉
-(void)backGroundViewPanAction:(UIPanGestureRecognizer *)gesture{
UIView *view = gesture.view;
if (gesture.state == UIGestureRecognizerStateBegan || gesture.state == UIGestureRecognizerStateChanged) {
CGPoint translation = [gesture translationInView:view.superview];
[view setCenter:(CGPoint){view.center.x + translation.x, view.center.y + translation.y}];
[gesture setTranslation:CGPointZero inView:view.superview];
}
}
#pragma mark -旋转
-(void)backGroundViewRotationAction:(UIRotationGestureRecognizer *)gesture{
self.transform = CGAffineTransformRotate(self.transform, gesture.rotation);
gesture.rotation = 0;
}
#pragma mark -长按
- (void)LongPressAction:(UILongPressGestureRecognizer *)longPress
{
if (longPress.state == UIGestureRecognizerStateBegan) {
if (self.delectedBlock) {
self.delectedBlock(self.model,self);
}
[self removeFromSuperview];
}
}
@end