Monday, February 25, 2013

Obj-c/UIDeviceOrientation: How to force the Device Orientation

Hi,

How's it going?
Today I got a fast tip in how to force your device orientation. Fast, quick and beautiful.

1) You have to put this piece of code somewhere in the class that you're using or in the AppDelegate. It's gonna depend on what you prefer, in my case I putted it in a specific class.


[[UIDevice currentDevice]beginGeneratingDeviceOrientationNotifications];


2) Add this to your .h or to the top of your .m . Do not forget to put something in the parenthesis different than 'Private', think something that Apple wouldn't use and put it their.


@interface UIDevice(MyDeviceInterface)
- (void) setOrientation:(UIInterfaceOrientation)orientation;
@end


3) Now be free to you this gorgeous method whenever you want in that specific class.


[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];


Enjoy!
Happy Coding.

No comments:

Post a Comment

Tweet