Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger a function when the iPhone is rotated 90 degrees?

Tags:

iphone

How do I detect the rotation of the iPhone for approximately 90 degrees? Additionally, I don't need/want the screen itself to rotate. I just want to call a function when the phone has been rotated. Thanks!

like image 471
john Avatar asked Jun 22 '09 20:06

john


2 Answers

Your view controller will be sent:

  -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

Implement it to do something when the phone is being rotated

After the rotation is done, you get:

  - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

Here it is in the docs (see Handling View Rotations)

http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html

like image 97
Lou Franco Avatar answered Nov 15 '22 06:11

Lou Franco


When you rotate the device, your view controller receives a didRotateFromInterfaceOrientation: message, with the old orientation. You can check the interfaceOrientation property to see the current rotation, and do something accordingly.

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
like image 23
Jesús A. Álvarez Avatar answered Nov 15 '22 05:11

Jesús A. Álvarez