How to set Interface Orientation programmatically in iOS 7 and iOS 6

In this tutorial, i am going to explain how to set the interface orientation programmatically or it will teach you how to identify /dictate  device orientation changes.
Detecting iOS Device rotation Code Snippet.

Step 1) Register a notification:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:UIDeviceOrientationDidChangeNotification object:nil];

2) Then you can test against the rotation on change

-(void) detectOrientation {
    if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) || 
        ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) {
        [self doLandscapeThings];
    } else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) {
        [self doPortraitThings];

Leave a Reply

Your email address will not be published. Required fields are marked *