iPhone application landscape mode doesn't work - iphone

Currently I have only portrait mode in iPhone application. I would like to permit landscape mode for one controller in application but unfortunately I'm not able to make it work.
I have these settings in my plist file:
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
</array>
And I implemented these methods in my controller:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
-(BOOL)shouldAutorotate
{
return YES;
}
I use navigation controller in the app so I realize that it might be the problem. I subclassed the UINavigationController and implemented again shouldAutorotateToInterfaceOrientation, supportedInterfaceOrientations and shouldAutorotate in the same way as above. Of course for I use subclassed navigation controller to show the controller which should have ability to rotate. I also tried to overwrite the methods of navigation controller by category but it also doesn't work.
I don't work on the application from the beginning, I inherited the codes. If there is some possibility how to restrict landscape globally it might be my case. For testing I use iPhone 6.0 simulator but my deployment target is 5.0. I appreciate any tips / help.

iOS6 also requires that you set a rootViewController for your window rather than adding the controller's view as a subview.
If you are doing something like this:
[window addSubview:someController.view];
then you can try changing it to this:
[window setRootViewController:someController];
Also look at this link. For ios6, Apple introduced these two methods :
supportedInter
faceOrientations:
shouldAutorotate
Hope it helps.
Shumais Ul Haq

Try this on Controller youwant to give landscape orientation
// override to allow orientations other than the default portrait orientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// return YES for supported orientations
return UIInterfaceOrientationIsLandscape(interfaceOrientation); // support only landscape
}

Go to target window.
Click on Summary tab.
iPhone/iPad Deployment info -> Set the supported interface orientations for iPhone & iPad as per your requirement. See following image for more reference.

Related

view does not rotate when orientation is upsidesidedown in ios 7

I tring to make app support all orientation. Its working fine but only upside down orientation is not working. I am using ios7. For upside down the view does not rotate. I tried following code
-(BOOL)shouldAutorotate
{
return yes;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll; // etc
}
My only second method is called but not first method. In infoPlist I enabled all the supported orientations.
Found the fix. Sourced mainly from: https://stackoverflow.com/a/12758715/394969
In a nutshell for people who land here first:
/* In your view controller */
// Add support for upside down
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
Also flip on all device orientations in project settings as outlined in #Jignesh Mayani's answer. If that doesn't immediatley fix your issue check the link above for how to work with nav controllers and tab controllers (they all must support the required interface orientations).
Confirm that you have check, Go your project setting and Check

How to support only portrait mode on an iPhone app

I have a strange problem in an iPhone app I'm developing. I want my app to support ONLY portrait mode, but for some reason I can't do it (device & simulator).
To support only portrait mode I did as follow:
In the TARGET summary section on Xcode, I chose only portrait.
All my ViewControllers implements shouldAutorotateToInterfaceOrientation
But as I said it won't work, and the strange result is that the app support ALL the orientations (portrait, upside down, landscape left, landscape right).
Any ideas?
this how I implement shouldAutorotateToInterfaceOrientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
NSLog(#"Checking orientation %d", interfaceOrientation);
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
I notice just now that when I rotate the phone I get this message:
"Two-stage rotation animation is deprecated. This application should
use the smoother single-stage animation."
What does it means?
On the Target Summary choose portrait only.
Go to info.plist file. Right Click open it as source code. And look for this line. For me in iPad its like this:
<key>UISupportedInterfaceOrientations~ipad</key>
Delete all other orientation and keep the only one which you need..Like this :
<array>
<string> UIInterfaceOrientationPortrait </string>
</array>
It is possible to have multiple ViewControllers on the screen. The UITabBarController is itself a UIViewController, and it only passes shouldAutorotateToInterfaceOrientation: requests to the viewControllers within if it chooses. The default implementation does this, but if you subclass it, the code XCode generates (as of iOS 5.1) does not.
check your plist and make sure the key there is set correctly.

UIView always loads in portrait mode

This one has me ripping my hair out. My iPad application is setup as follows:
In my app delegate I have this:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
in my info.plist I have:
Initial Interface Orientation = UIInterfaceOrientationLandscapeLeft
In my first view controller that is loaded from the app delegate I have:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations.
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
In my second view controller I have:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations.
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
Finally the views in both nibs are set to landscape in Interface Builder. The application starts in landscape mode and there is a button that when pressed assigns the second view to the first view:
self.view = secondView.view;
the problem is that even though everything is in landscape the new view is always loaded in portrait mode? Please any help on this would be very very appreciated!
This is the bit you want to change. This is what sets the allowed initial orientations. Change it to suit your needs.
It's in the summary tab of the Target's settings.
Or. if you aren't using Xcode 4 yet - you can set the orientations in the Info.plist:
And so you can see all the keys:

iOS how to stop view rotate

I want my iPad app to stop rotation as you rotate the iPad. I want to stop rotate every view.
Any ideas help?
if you want stop rotation for whole app then simply in app info.plist file changed Supported interface orientations ,Initial interface orientation property to portrait or landscape depends on you
In iOS6 shouldAutorotateToInterfaceOrientation has be deprecated. Override both supportedInterfaceOrientations and preferredInterfaceOrientationForPresentation instead.
Please see
Just check the auto-resizing property of your view controller.
(Fixed syntax error)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationPortrait)
return YES;
return NO;
}
In My Project's info.plist I have deleted some key on the iPad Supported interface orientations like the following image (I have only given support for the portrait orientation)
The main idea of global controllable rotation lock is to write UIViewController category containing lock mechanism for every view controller.
You simply need to modify supportedInterfaceOrientations method globally
- (NSUInteger)supportedInterfaceOrientations
{
return __orientation;
}
Here __orientation is the static variable which can be set via category method.
The full realization of the category is presented here
Please update your projectname.plist like this. Supported interface orientations have only one object "Portrait (bottom home button)"
I strongly advise against stop rotation on iPad because supporting rotation is a must on the iPad. This is because the iPad does not have a normal way in which it will be held unlike the iPhone, which is normally held in portrait view (AKA Vertical). So you have to leave the choice to the user to eventually lock the orientation
The HIG do not actually state this as a requirement, but as a recommendation but there are many app that was rejected by this issue.
By the way if you want to this for a limit number of view controller you should implement:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(interfaceOrientation == UIInterfaceOrientationPortrait){
return YES;
}
}

How to restrict my app to landscape mode?

I have my iPad application created using the SplitView template.
I wonder what is the best way to restrict my application to landscape mode?
I have tried overriding shouldAutorotateToInterfaceOrientation: method in DetailViewController.m
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
but 4.2 GM is still buggy and it fails to show the controller view. What other choices do I have?
Thanks in advance.
UPDATE1
I have already filed a bug report:
Bug ID #8620135
My app is almost finished and I have to find a work-arround since I don't think they are going to solve this before 4.2 officially comes out (GM is already out!)
In order to recreate the bug, just use SplitView template and override above method in any of the UIViewControllers (RootViewController or DetailViewControllers)
UPDATE2
I have found a work-around. (See UPDATE3 for the complete work-around)
Set UISupportedInterfaceOrientations only to support Landscape , this will force the app to start in landscape mode allowing DetailViewController to start correctly(hence shown correctly)
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
But if you rotate the device, it turns Portrait mode!!!, so is still necessary to override shouldAutorotateToIntercafeOrientation: as above
Discussion:
If this wouldn't be a bug I would expect a warning or execution error, exception or something when starting the app in a orientation that is not supported by the view controller. Besides, why only DetailViewController does not show? If this would be specification, then RootViewController should also fail to load then. Don't you think?
thanks for you help... ;)
UPDATE3
After further tests I have realized that above work-around does not work in some cases. For example when starting the app when the device is in landscape won't work!.
The real problem seems to be that in iOS4.2GM UISplitViewController needs all its controllers have all rotations to be available at its load time. So is necessary to trick him so it loads in Landscape mode and then not allow him to rotate its view controllers.
So here is the new work-around for this annoying iBug.
Step1:
Set Info.plist like so:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
Step2
Set a new flag in DetailViewController.m or .h (from SplitView Template)
BOOL lockRotation = NO; //WORK-ARROUND: Bug ID# 8620135.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//WORK-ARROUND: Bug ID# 8620135.
if (lockRotation) {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}else{
return YES;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
//set NO here since this is called before shouldAutorotateToInterfaceOrientation method is called
lockRotation = NO; //WORK-ARROUND: Bug ID# 8620135.
}
- (void)viewDidAppear:(BOOL)animated {
//set YES as soon as possible, but after shouldAutorotateToInterfaceOrientation method was called
lockRotation = YES; //WORK-ARROUND: Bug ID# 8620135.
[super viewDidAppear:animated];
}
IMPORTANT NOTE:
Please note that this bug only appears when the UISplitViewController is loaded and not everytime
the its view appears. Hence, to see this bug make sure the app was terminated before.
I asked a question with a bounty of 500 that seems to be the same thing you're facing.
From my limited experience it is much easier to make a landscape-only iPhone app than a landscape-only iPad app. I'm not sure why there is any difference, but the steps Apple says to take to make it landscape-only do not work on their own.
Try this (it works):
-(BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation {
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
return YES;
}
else
{
return NO;
}
}
Check out this iPhone app in landscape mode, if you haven't already. I was going to suggest simply adding UISupportedInterfaceOrientations to your Info.plist and specifying the two landscape orientations. But, apparently, this is not sufficient, according to answers to cited question.
I believe this is a BUG, I faced this problem also. It is something to do with
UIInterfaceOrientationLandscapeLeft
To replicate this situation:
1) Create a new iPad project using UISplitViewController template
2) Edit info.plist
Supported interface orientations
-Landscape (left home button)
-Landscape (right home button)
3) DetailViewController.m
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// return YES;
NSLog(#"RotateToInterface:[%d] vs LandscapeLeft[%d]", interfaceOrientation, UIInterfaceOrientationLandscapeLeft);
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft;
}
4) Run it....You will see a blank black view. and no matter how you turn. "UIInterfaceOrientationLandscapeLeft" never detected.
By the way, nacho4d's adding BOOL check work-around is working. Thumbs UP :)