Created
April 1, 2014 21:09
-
-
Save d3signerd/9923277 to your computer and use it in GitHub Desktop.
Extended UIPanGestureRecognizer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SimpleUIPanGestureRecognizer.h | |
// Playback | |
// | |
// Created by KS on 4/1/14. | |
// Copyright (c) 2014 ks. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
#import <UIKit/UIGestureRecognizerSubclass.h> | |
@interface SimpleUIPanGestureRecognizer : UIPanGestureRecognizer | |
{ | |
CGPoint fullDistance; | |
CGPoint startPoint; | |
CGPoint moveDifference; | |
CGPoint movePoint; | |
} | |
// UIGestureRecognizerSubclass Methods | |
- (void) reset; | |
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; | |
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; | |
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; | |
- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event; | |
// Getters | |
- (CGPoint) totalDistance; | |
- (CGPoint) distanceMoved; | |
- (CGPoint) getStartPoint; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SimpleUIPanGestureRecognizer.m | |
// Playback | |
// | |
// Created by KS on 4/1/14. | |
// Copyright (c) 2014 ks. All rights reserved. | |
// | |
#import "SimpleUIPanGestureRecognizer.h" | |
@implementation SimpleUIPanGestureRecognizer | |
#pragma mark - UIGestureRecognizerSubclass Methods | |
- (void)reset | |
{ | |
// Reset Points | |
startPoint = CGPointMake( 0 , 0 ); | |
moveDifference = CGPointMake( 0 , 0 ); | |
movePoint = CGPointMake( 0 , 0 ); | |
[super reset ]; | |
} | |
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; | |
{ | |
[super touchesBegan:touches withEvent:event ]; | |
// Save Start Point | |
startPoint = [self locationInView:self.view ]; | |
movePoint = [self locationInView:self.view ]; | |
fullDistance = CGPointMake( 0 , 0 ); | |
} | |
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event | |
{ | |
[super touchesMoved:touches withEvent:event ]; | |
// Instantly Start Gesture | |
[self setState:UIGestureRecognizerStateChanged ]; | |
// Save difference | |
CGPoint newMovePoint = [self locationInView:self.view ]; | |
moveDifference = CGPointMake( newMovePoint.x - movePoint.x , newMovePoint.y - movePoint.y ); | |
// Save Move Point | |
movePoint = newMovePoint; | |
// Save total | |
CGPointMake( movePoint.x - startPoint.x , movePoint.y - startPoint.y ); | |
} | |
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event | |
{ [super touchesEnded:touches withEvent:event ]; } | |
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event | |
{ [super touchesCancelled:touches withEvent:event ]; } | |
#pragma mark - Getters | |
- (CGPoint) distanceMoved | |
{ return moveDifference; } | |
- (CGPoint) getStartPoint | |
{ return startPoint; } | |
- (CGPoint) totalDistance | |
{ return fullDistance; } | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment