You can simply determine the start and stop of the touch and calculate the angle with two points.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
To calculate the angle between them, you can use something like this:
static inline CGFloat angleBetweenLinesInRadians(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint line2End) { CGFloat a = line1End.x - line1Start.x; CGFloat b = line1End.y - line1Start.y; CGFloat c = line2End.x - line2Start.x; CGFloat d = line2End.y - line2Start.y; CGFloat line1Slope = (line1End.y - line1Start.y) / (line1End.x - line1Start.x); CGFloat line2Slope = (line2End.y - line2Start.y) / (line2End.x - line2Start.x); CGFloat degs = acosf(((a*c) + (b*d)) / ((sqrt(a*a + b*b)) * (sqrt(c*c + d*d)))); return (line2Slope > line1Slope) ? degs : -degs; }
So, to find the angle of the horizontal line, you can do something like this
CGFloat angle=angleBetweenLinesInRadians(startPoint, endPoint, startPoint, CGPointMake(startPoint.x + 10, startPoint.y));
That would be such an angle
________ \ this angle \ \ x
Hope this helps
CHANGE the best way
What you can do is subclass UIGestureRecognizer
#import <UIKit/UIGestureRecognizerSubclass.h>
Then you implement these 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;
Each of them is used to define and set the state property for gestures.
Here is a complete example: http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html