Thursday, October 8, 2009

Two Finger Rotate

Here is an Xcode project that shows how to do the two-finger rotate gesture. It's pretty straightforward, it just uses a CGAffineTransform to rotate the text on the screen to the same angle as the angle between the user's two fingers.

This project does not deal with the fact that touches come into the responder methods unordered, so you may notice some minor glitches if you try and do more than a 180° rotation. That's a subject for a future blog posting.



10 comments:

Conor McCluskey said...

Yeh I noticed that glitch when I was implementing a 2 finger rotation. Every so often, the object would flip 180. I had to rewrite my touch event handling to keep track of each individual touch event throughout the touch phases. It got a lot trickier with an OS bug that failed to fire touchesEnded events every one in a while though.

K. A. Barber said...

I've run into the failed touchesEnded issue before also. Thought it was something was doing wrong. Spent a lot of time trying to figure out exactly what was happening. Anyone have info on the issue?

Zakir Hussain said...

Blue Silicone Skin Case for Apple iPod Touch 2nd Gen. Made of high quality silicone skin. Designed to perfectly fit Apple iPod Touch 2nd Gen with precise cuts to access all the controls and protects your Ipod or Iphones from dust and harming

Unfit for Print said...

The ordering issue is easy enough to get around if you store an ordered list of the touch events' hashes (e.g. [myArray addObject:[touchEvent hash]]).

Slava said...

Just post a sample with MKMapView rotation with iPhone ccelerometer: http://iphone-dev-tips.alterplay.com/2009/11/map-view-rotation-with-accelerometer.html
Hope it'll help anybody.

Bernd said...

There is a simple way around your glitches:

in angleBetweenPoints:

instead of atan(height/width)
use atan2(height,width)

And then there is another "glitchy" point in your code:
instead of
if (self.initialAngle = 0.0)
it should REALLY better be
if (self.initialAngle == 0.0)
(yeah, the old C-mistake we all know and love :o)

Thanks for your code!
Captain Fim

Koddy said...

I agree that "Two Finger Rotate"
is subject for a future blog posting. I'd like to learn some more about it.
I also would like to know what viagra online is.

javieth said...

I must to say this blog catched my attention and i am completely satisfy what i read here. Really wonderful!! I think our fingers always get a good function for every task that we need to do. So we need to appreciate and take care every part of our body.
Actually our fingers can be erotic too, if you are interested to have a great experience i advice first to buy viagra and then you´ll tell me.

Edwin said...

scrub m65 kamagra attorney lawyer body scrub field jacket lovegra marijuana attorney injury lawyer

h4ns said...

What youre saying is completely true. I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I also love the images you put in here. They fit so well with what youre trying to say. Im sure youll reach so many people with what youve got to say.

Arsenal vs Huddersfield Town live streaming
Arsenal vs Huddersfield Town live streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Notts County vs Manchester City Live Streaming
Notts County vs Manchester City Live Streaming
Bologna vs AS Roma Live Streaming
Bologna vs AS Roma Live Streaming
Juventus vs Udinese Live Streaming
Juventus vs Udinese Live Streaming
Napoli vs Sampdoria Live Streaming
Napoli vs Sampdoria Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
AS Monaco vs Marseille Live Streaming
AS Monaco vs Marseille Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Technology News | News Today | Live Streaming TV Channels