-
Notifications
You must be signed in to change notification settings - Fork 6
/
MVNSContentView.m
76 lines (63 loc) · 1.82 KB
/
MVNSContentView.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// MVNSContentView.m
// Chat
//
// Created by Michaël Villar on 5/8/13.
//
//
#import "MVNSContentView.h"
@interface MVNSContentView ()
@property (readwrite) BOOL scrolled;
@property (readwrite) BOOL firstScroll;
@end
@implementation MVNSContentView
@synthesize scrolled = scrolled_,
firstScroll = firstScroll_;
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if(self)
{
scrolled_ = NO;
firstScroll_ = NO;
}
return self;
}
#pragma mark Event Handling
- (void)beginGestureWithEvent:(NSEvent *)event
{
[super beginGestureWithEvent:event];
self.scrolled = YES;
self.firstScroll = YES;
}
- (void)endGestureWithEvent:(NSEvent *)event
{
[super endGestureWithEvent:event];
if(self.scrolled || self.firstScroll)
{
[[NSNotificationCenter defaultCenter] postNotificationName:kMVNSContentViewDidEndSwipeNotification
object:self];
}
self.scrolled = NO;
}
- (void)scrollWheel:(NSEvent *)event
{
if(self.scrolled)
{
if(self.firstScroll && event.scrollingDeltaY != 0)
self.scrolled = NO;
else {
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat:event.scrollingDeltaX], @"deltaX",
nil];
[[NSNotificationCenter defaultCenter] postNotificationName:kMVNSContentViewDidSwipeWithDeltaXNotification
object:self
userInfo:userInfo];
}
if(self.firstScroll && (fabs(event.scrollingDeltaX) > 3 || fabs(event.scrollingDeltaY) > 3))
self.firstScroll = NO;
}
if(!self.scrolled || self.firstScroll)
[super scrollWheel:event];
}
@end