It looks like you're new here. If you want to get involved, click one of these buttons!

HoofSC
Posts: **41**Registered Users

Hi,

Banging my head against a wall here. I think I'm missing something elementary.

Here is what I would like to accomplish:

1. Display a UIImageView with a graphic of a volume knob.

2. Detect swipeRight/swipeLeft gesture.

3. Rotate the image in radians + or - based on the direction of the swipe.

Eventually I would like to be able to "scale" the rotation based on the distance of the swipe, but for now, I'm just trying to get a basic working model.

Here's the problem:

I can do all 3 steps, however I am using a CGAffineTransformMakeRotation(radians)

If I swipe in the opposite direction, it treats the original "zero angle" AS 0 radians, whereas I need to 'reset' the zero angle after the first animation.

Any thoughts? Is it just simple logic I'm missing??

Thanks in advance.

Banging my head against a wall here. I think I'm missing something elementary.

Here is what I would like to accomplish:

1. Display a UIImageView with a graphic of a volume knob.

2. Detect swipeRight/swipeLeft gesture.

3. Rotate the image in radians + or - based on the direction of the swipe.

Eventually I would like to be able to "scale" the rotation based on the distance of the swipe, but for now, I'm just trying to get a basic working model.

Here's the problem:

I can do all 3 steps, however I am using a CGAffineTransformMakeRotation(radians)

If I swipe in the opposite direction, it treats the original "zero angle" AS 0 radians, whereas I need to 'reset' the zero angle after the first animation.

Any thoughts? Is it just simple logic I'm missing??

```
-(void)processSwipeRight:(NSSet*)touches withEvent:event {
float singleTurnRadians = 36 * 3.14157 / 180;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.5];
CGAffineTransform transform = CGAffineTransformMakeRotation(singleTurnRadians);
knobImageView.transform = transform;
[UIView commitAnimations];
notch += 1;
}
-(void)processSwipeLeft:(NSSet*)touches withEvent:event {
float singleTurnRadians = 36 * 3.14157 / 180;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.5];
CGAffineTransform transform = CGAffineTransformMakeRotation(-singleTurnRadians);
knobImageView.transform = transform;
[UIView commitAnimations];
notch -= 1;
}
```

Thanks in advance.

Post edited by HoofSC on

## Replies

802Registered Users41Registered UsersThanks Scott

Any suggestion on how to do that exactly? I've tried a number of things including:

But that still does not working properly. Somehow the behavior of CGAffineTransformMakeRotation(angle) doesn't seem to get the job done...

Any code suggestions?

802Registered UsersYou could calculate the degrees around using atan2(?) relative to the the center.

(i.e. touch is x,y relative to center xy so it's z degrees)

As you move your finger you recalc and use the difference to rotate.

41Registered UsersI do want interaction, but I guess I'm confused as to the way to "set" the rotation. The CGAffineTransformMakeRotation on every swipe method call is giving me weird erratic results (using the code block above) whether I call the UIView animation methods or not...

Something simple I'm missing?

----EDITED

Thanks Scott. It turns out that the rotation does work. It appears to be a problem with my swipe method detection that is giving erratic results.

Here is what I have: