My app is only for iphone
device (both iphone 4 and 5) and built to support only ios 6
.
My whole app only supports portrait
mode. But there is one view called "ChatView
" , which i want to support both landscape
and portrait
modes.
I have set the required device rotations as follows -
I have also tried following code to support rotation in "ChatView" -
-(BOOL)shouldAutorotate { return YES; } -(NSUInteger)supportedInterfaceOrientations { 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.
Thanks.....
Use the shouldAutorotate and the supportedInterfaceOrientations method in the ViewController you want to display in landscape and portrait mode: This method should override the storyboard-settings. Hey Christian, this answer only seems to work if you subclass the UINavigationController and return self.
Go it the main and select TARGETS then select Info tab (the plist) and open Supported inferface orientations (iPhone) the click on the ones that you do not need. Just leave Portrait(bottom home button) . That should make the UI stay one way.
Set the supportedInterfaceOrientations property of specific UIViewControllers like this: class MyViewController: UIViewController { var orientations = UIInterfaceOrientationMask. portrait //or what orientation you want override var supportedInterfaceOrientations : UIInterfaceOrientationMask { get { return self.
Simple but it work very fine. IOS 7.1 and 8
AppDelegate.h
@property () BOOL restrictRotation;
AppDelegate.m
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { if(self.restrictRotation) return UIInterfaceOrientationMaskPortrait; else return UIInterfaceOrientationMaskAll; }
ViewController
-(void) restrictRotation:(BOOL) restriction { AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate; appDelegate.restrictRotation = restriction; }
viewDidLoad
[self restrictRotation:YES]; or NO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With