Reputation: 1288
Is there a way to detect if the rotation done by the user is in clockwise or counter clockwise direct???
I searched for that but couldn't find an answer !
My code looks like this:
UIGestureRecognizer *recognizer;
recognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(spin)];
[self.rotating addGestureRecognizer:recognizer];
[recognizer release];
Upvotes: 2
Views: 3313
Reputation: 719
Swift version - imagine you've connected your UIRotationGestureRecognizer to an IBAction and are passing in the UIRotationGestureRecognizer as argument recognizer
. You could very easily test direction with the following:
if recognizer.rotation < 0 {
print("Negative rotation value means anticlockwise rotation detected")
} else if recognizer.rotation > 0 {
print("Positive rotation value means clockwise rotation detected")
}
Upvotes: 1
Reputation: 22264
the rotation
property will tell you the rotation in radians. A negative value would indicate the rotation is clockwise, and a positive value indicates counter-clockwise.
Example:
UIGestureRecognizer *recognizer;
recognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(spin:)]; // <-- Note the colon after the method name
[self.rotating addGestureRecognizer:recognizer];
[recognizer release];
- (void)spin:(UIGestureRecognizer *)gestureRecognizer {
CGFloat rotation = gestureRecognizer.rotation;
if (rotation < 0) {
// clockwise
} else {
// counter-clockwise
}
}
Upvotes: 4