How To Restrict Changing Into Landscape Iphone? - iphone

I do have five view controllers, and i am navigating from first view Controller to end view Controller (fifth view controller)
In middle i do third view i need to do orientation. for landscape and potrait mode.
and from there it need to be potrait mode only.
I added this delegate method for orientation in fouth viewController . but its not effecting
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
//Support orientation for Portrait
return (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation==UIInterfaceOrientationPortrait );
}

I think your changing orientation in your first view.Open your third view and write this method then change whatever you want...i think you should write this in all of the view expect third view...
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Now in your third view write your code....
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
//Support orientation for Portrait
return NO;
}

just do.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation == UIInterfaceOrientationLandscape)
return NO;
else
return YES;
}

Related

Only statusbar is rotating to Landscape (iPhone)

In One of my Viewcontroller that supports only Portrait orientation. On my
device when rotate the status bar is rotating to landscape
orientation. The rest of the view remains in Portrait mode. I want to prevent the roation of statusbar. This
problem is happening only in IOS7
// Overridden function to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
// iPhone: support only upright portrait
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
else
{
// iPad: any orientation is OK
return YES;
}
}
// For iOS6.0 Rotate
- (BOOL)shouldAutorotate
{
return NO;
}
Use this method to keep it in Portrait view :
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;

Keep all views portrait except one

Right I have done a lot of research on this and have hit a block.
I am developing an app which has multiple view controllers. I have the 'homepage', if you will, which all the others views can be access from (this ViewController.m). I also then have a UINavigationController.m attached to the ViewController.m to allow a full navigation bar etc.
My problem is that I am wanting all views to be shown in portrait EXCEPT one view, which I only want in landscape. In my app options, I have set it to enable all orientations and then I was reading that you should override the main orientation in your root view controller (which I assume is the navigation controller?), so I add:
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
This overrides everything and only portrait works. I have then tried adding:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
To the view that I want to have in landscape only but it fails to work in the simulator.
Can anyone provide me with a solution? :/
(I would like iOS5 and iOS6 support if possible)
[EDIT]
I should add, I haven't edited AppDelegate in any way.

In tabbar application we want to view only some view to landscape and some to portrait in iphone

In my application there are three tabs in second tab one viewcontroller in that i want to view only in portrait mode but i m not able to view in that format...so any one have right solution then answer here...
add this methods to your second view controler :
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}

Make a UiViewController stay in portrait mode iOS6 VS iOS5

I'm building an app for iOS5 and iOS6. I have this UIViewController inside a UINavigationController and I want it to stay in portrait mode.
The code works for iOS5, but not in iOS6.
// iOS5 rotation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation == UIInterfaceOrientationPortrait)
return YES;
else
return NO;
}
// iOS6 rotation
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
What's the problem here??? On SO I've found lot's of similar questions, but generally the answers are not working for me.
EDIT:
Maybe I was not precise, but I need a SINGLE view controller (the homepage of my app) to stay in portrait mode and not all the app.
First of all, A lot depends on with which controller is your UIViewController embedded in.
Eg, If its inside UINavigationController, then you might need to subclass that UINavigationController to override orientation methods like this.
subclassed UINavigationController (the top viewcontroller of the hierarchy will take control of the orientation.) needs to be set it as self.window.rootViewController.
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
From iOS 6, it is given that UINavigationController won't ask its UIVIewControllers for orientation support. Hence we would need to subclass it.
MOREOVER
Then, For UIViewControllers, in which you need only PORTRAIT mode, write these functions
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait);
}
For UIViewControllers, which require LANDSCAPE too, change masking to All.
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskAllButUpsideDown);
//OR return (UIInterfaceOrientationMaskAll);
}
Now, if you want to do some changes when Orientation changes, then use this function.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
}
VERY IMPORTANT
in AppDelegate, write this. THIS IS VERY IMP.
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return (UIInterfaceOrientationMaskAll);
}
If you want to provide only Portrait mode for all your viewcontrollers, then apply the portait mask. i.e UIInterfaceOrientationMaskPortrait
Otherwise, if you want that some UIViewControllers stay in Portrait while others support all orientations, then apply an ALL Mask. i.e UIInterfaceOrientationMaskAll
Try out this :
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
UIInterfaceOrientationMask orientationMask = UIInterfaceOrientationMaskPortrait;
return orientationMask;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
This should work in order to support the portrait mode only.

How to disable portrait orientation on UINavigationController rootViewController

I have a class, HomeView, as the rootViewController of a UINavigationController on my iPad application. Only landscape orientation is set in the info.plist file and HomeView does not implement shouldRotateToInterfaceOrientation:, however the view is rotating for both orientations while the simulator is rotating.
How do I only use the landscape orientations in my UIViewController?
If you do not implement shouldAutorotateToInterfaceOrientation: the runtime will call the method on the Super class, UIViewController.
Instead you should respond appropriately to the method with the orientations you want to rotate to:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
BOOL shouldAutorotate = NO;
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft
|| interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
shouldAutorotate = YES;
}
return shouldAutorotate;
}
Take a look at the UIInterfaceOrientation reference page and the UIViewController's shouldAutorotateToInterfaceOrientation: reference page for more information.
You shouldn't remove the shouldAutorotateToInterfaceOrientation method; that will not stop the interface from rotating, it will only not execute any code that you could have in that method. You should instead try something like this (assuming that you don't ever want the interface to rotate):
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}