-
Notifications
You must be signed in to change notification settings - Fork 3
/
PEResizeControl.m
58 lines (46 loc) · 2.08 KB
/
PEResizeControl.m
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
//
// PEResizeControl.m
// PhotoCropEditor
//
// Created by kishikawa katsumi on 2013/05/19.
// Copyright (c) 2013 kishikawa katsumi. All rights reserved.
//
#import "PEResizeControl.h"
@interface PEResizeControl ()
@property (nonatomic, readwrite) CGPoint translation;
@property (nonatomic) CGPoint startPoint;
@end
@implementation PEResizeControl
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:CGRectMake(frame.origin.x, frame.origin.y, 44.0f, 44.0f)];
if (self) {
self.backgroundColor = [UIColor clearColor];
self.exclusiveTouch = YES;
UIPanGestureRecognizer *gestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[self addGestureRecognizer:gestureRecognizer];
}
return self;
}
- (void)handlePan:(UIPanGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
CGPoint translationInView = [gestureRecognizer translationInView:self.superview];
self.startPoint = CGPointMake(roundf(translationInView.x), translationInView.y);
if ([self.delegate respondsToSelector:@selector(resizeControlViewDidBeginResizing:)]) {
[self.delegate resizeControlViewDidBeginResizing:self];
}
} else if (gestureRecognizer.state == UIGestureRecognizerStateChanged) {
CGPoint translation = [gestureRecognizer translationInView:self.superview];
self.translation = CGPointMake(roundf(self.startPoint.x + translation.x),
roundf(self.startPoint.y + translation.y));
if ([self.delegate respondsToSelector:@selector(resizeControlViewDidResize:)]) {
[self.delegate resizeControlViewDidResize:self];
}
} else if (gestureRecognizer.state == UIGestureRecognizerStateEnded || gestureRecognizer.state == UIGestureRecognizerStateCancelled) {
if ([self.delegate respondsToSelector:@selector(resizeControlViewDidEndResizing:)]) {
[self.delegate resizeControlViewDidEndResizing:self];
}
}
}
@end