2
// UOPanGestureRecognizer.m
5
// Created by Paul Hummer on 1/26/13.
6
// Copyright (c) 2013 Canonical. All rights reserved.
9
#import "UODownloadPanGestureRecognizer.h"
10
#import <UIKit/UIGestureRecognizerSubclass.h>
12
@interface UODownloadPanGestureRecognizer () {
17
@implementation UODownloadPanGestureRecognizer
18
@synthesize threshold;
20
- (id)initWithTarget:(id)target action:(SEL)action {
21
self = [super initWithTarget:target action:action];
22
if (self == nil) { return self; }
28
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
29
CGPoint touch = [[touches anyObject] locationInView:self.view];
30
if (!CGRectEqualToRect(self.handle.bounds, CGRectZero) &&
31
!CGRectContainsPoint(self.handle.bounds, touch)) {
32
self.state = UIGestureRecognizerStateCancelled;
36
[super touchesBegan:touches withEvent:event];
37
start = [[touches anyObject] locationInView:nil];
40
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
41
for (UITouch *touch in touches) {
42
CGPoint point = [touch locationInView:nil];
43
CGFloat offset = point.x - start.x;
45
self.state = UIGestureRecognizerStateCancelled;
49
/* If we want to fire the event as soon as the threshold is reached,
50
we do it here. As it is, we require a release of the finger.
53
[super touchesMoved:touches withEvent:event];
56
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
57
CGPoint point = [[touches anyObject] locationInView:nil];
58
CGFloat offset = point.x - start.x;
60
if (fabs(offset) > self.threshold) {
61
[super touchesEnded:touches withEvent:event];
63
self.state = UIGestureRecognizerStateCancelled;