-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMHCardView.m
37 lines (29 loc) · 1.16 KB
/
MHCardView.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
//
// Created by Florian on 21/04/14.
//
// To change the template use AppCode | Preferences | File Templates.
//
#import "MHCardView.h"
@implementation MHCardView
-(void)awakeFromNib{
[super awakeFromNib];
[self setup];
}
-(void)setup{
UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(didPan:)];
[self addGestureRecognizer:recognizer];
}
-(void)didPan:(UIPanGestureRecognizer *)recognizer{
CGPoint point = [recognizer translationInView:self.superview];
self.center = CGPointMake(self.center.x, self.center.y + point.y);
[recognizer setTranslation:CGPointZero inView:self.superview];
if (recognizer.state == UIGestureRecognizerStateEnded) {
CGPoint velocity = [recognizer velocityInView:self.superview];
velocity.x = 0;
[self.delegate cardView:self draggingEndedWithVelocity:velocity lastTouchLocationInSuperview:point];
} else if (recognizer.state == UIGestureRecognizerStateBegan) {
[self.delegate MHCardViewBeganDragging:self];
}
//[[NSNotificationCenter defaultCenter] postNotificationName:MHCardDidDragNotificationName object:self];
}
@end