Rohan Rohan - 1 year ago 189
Objective-C Question

How to allow only single UIViewController to rotate in both Landscape and Portrait direction?

My app is only for

device (both iphone 4 and 5) and built to support only
ios 6

My whole app only supports
mode. But there is one view called "
" , which i want to support both

I have set the required device rotations as follows -

enter image description here

I have also tried following code to support rotation in "ChatView" -

return YES;

return UIInterfaceOrientationMaskLandscape;

But it could not rotate that view.

I have searched a lot for this , but could not be able to find the solution for my issue.

And also in "ChatView" there are some objects like buttons, textfields whose frames are set programmaticaly. So i want to know should i have to set frames of all those objects for landscape mode also?

Please help me.


Answer Source

I think if you want to support just one viewcontroller rotation, it is not possible since application will follow orientations set by you in .plist file. An alternate you can follow is to support your app for both landscape and portrait, freeze all viewcontrollers rotation to portrait except for chat view.


To subclass UINavigationController, create a new file with name e.g. CustomNavigationController and make it subclass of UINavigationController.

.h file

#import <UIKit/UIKit.h>

@interface CustomNavigationController : UINavigationController


.m file

#import "CustomNavigationController.h"

@interface CustomNavigationController ()


@implementation CustomNavigationController

    return NO;

    return UIInterfaceOrientationMaskAll;

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    return UIInterfaceOrientationIsPortrait(interfaceOrientation);


Set the class of your UINavigationController in your main class xib as CustomNavigationController. Hope it helps ypu..

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download