I need to support only portrait orientation in my app. How can I do it? I have tried adding
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
and
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationPortrait;
}
But it does't help - the view rotates anyway.
Thanks in advance!
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientationshould return a BOOL which is NOin your case.
This should be:
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return interfaceOrientation == UIInterfaceOrientationPortrait
|| interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ;
}
In XCode 5 (not sure about earlier versions), if you want on support portrait mode only across the whole app, go to Project Settings->General->Deployment info
and uncheck Upside Down, Orientation Left, and Orientation Right.
This is probably the easiest way to do it now.
For iOS 6, it seems you need to add/override this method too,
-(BOOL)shouldAutorotate {
return NO;
}
Related
I am developing a game in xcode using cocos2d-x 2.2.3. I want to change the mode from landscape to portrait. I used the following code in rootviewcontroller.mm file. But still its not working. Please anyone can help me. Thanks
return UIInterfaceOrientationIsPortrait( interfaceOrientation );
In your Rootviewcontroller.mm class change the code as following.
- (void)didFinishBannerViewActionNotification:(NSNotification *)notification
{
NSLog(#"didFinishBannerViewActionNotification");
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsPortrait( interfaceOrientation );
}
- (NSUInteger) supportedInterfaceOrientations{
#ifdef __IPHONE_6_0
return UIInterfaceOrientationMaskPortrait;
#endif
}
and in the xcode click your project name and in the general category change the Device orientation to portrait. I hope it will work.
My app works only in Landscape.
Thus I set the Initial Orientation and Supported Orientation at LandScape Home Right.
However, initial launch orientation always becomes Portrait.
After navigating to next page and return, the orientation is correct.
This might be the similar question to the following, In IOS 6 on iPad, initial rotation is always portrait, after that it always rotates correctly
But the solution there is not working as the 'handleRotationFor' gives warning:
instanceMethod -handleRotationFor is not found (return type defaults to 'id')
How should I fix this error?
Please help
project Targets --> click on "Summary" tab and choose your Orientation in "Supported interfaces Orientations"
In Xcode in the files pane click on your project and then select target from right pane. Then in Summary tab see supported orientations. Only select Landscape right. Also you can implement
-(NSUInteger)supportedInterfaceOrientation {
return UIInterfaceOrientationMaskLandscapeRight;
}
in your app delegate
In Xcode under summary tab make sure portrait and upside down are not pressed down. Also Add these three functions.
// *********************
// ios6 orientation support
// *********************
- (BOOL)shouldAutorotate
{
UIInterfaceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
return NO;
}
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
return NO;
}
else
{
return YES;
}
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
return NO;
}
else
{
return YES;
}
}
Check the supported orientations in the info.plist of the app. Check and set orientations in the nib file as well.
You can check orientations by using [[UIDevice currentDevice] orientation]
I have an iPad app that supports UIDeviceOrientationPortrait and UIDeviceOrientationLandscapeLeft.
I did include this method :
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft );
}
The issue I have is that I need it to load in the UIDeviceOrientationLandscapeLeft mode, just for the load, because my UI controls will be setup properly. how can I force it only once on load.
One thing I wanna note is that this has to be min iOS 5.
I recently had similar problem, but I wanted to change from Landscape to Portrait by force, I knew in old versions there were built in methods but unfortunately we are never sure when and what is working for us, but I gave this code a try and It worked for me, but my scenario was to forcing from landscape to portrait, which is opposite to your scenario, but anyways it works, here is the code possibly for your scenario;
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
-(void)viewWillAppear:(BOOL)animated {
UIApplication* application = [UIApplication sharedApplication];
if (application.statusBarOrientation != UIInterfaceOrientationLandscapeLeft)
{
UIViewController *c = [[UIViewController alloc]init];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];
}
[super viewWillAppear:animated];
}
EDIT working on IOS 6.1 I have added two more methods which I did not add in my previous post, I add now all what is working for my application...
- (BOOL)shouldAutorotate
{
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
the idea is to check the statusbar orietnation and add and dismiss a modalViewController and it works for me to force from one to another orientation.
Even if this answer is not what you expected:
Give yourself a favor: it is really complex to force the device into a specific orientation.
You can search here on SO, what all works and does not work, and works in 6.1 and not in 6.01. and so on.
So fastest and safest is, to fix your code such that it can corectly initialize in both orientations.
Despite any app Info.plist settings or -shouldAutorotateToInterfaceOrientation: (or -shouldAutorotate) method overrides, view controllers start off in portrait and are then rotated into landscape by iOS.
What is preventing your UI layout from being setup properly?
Update in the Project Settings OR the info file.
In iOS 6.x you should override supportedInterfaceOrientations.
Try also preferredInterfaceOrientationForPresentation.
Does anyone know how to set the interface orientation for the ZBar SDK? I need it to work in landscape view and not portrait. I tried adding [reader shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight];but it didn't work. Any ideas?
Create a wrapper class around ZBarReaderView and add the iOS 6 methods:
-(BOOL) shouldAutorotate
{
return NO;
}
-(NSUInteger) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
Then use the class you created over the built in ZBar one, make sure you keep the old iOS 5 methods in the same controller:
- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscape);
}
and also:
self.reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationMaskLandscape);
I know it's late, but I just got around to doing this myself for iOS 6.
I got the same issue and resolved it symply !
I just needed to call :
[reader willRotateToInterfaceOrientation: toInterfaceOrientation duration: duration];
within the willRotate... of the view controller that contains the ZbarReaderView.
I'm not sure exactly what you mean but maybe this help you ...
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeLeft animated:NO];
or
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft];
Can anyone explain me what's going on? I use this method
- (BOOL)shouldAutorotateToInterfaceOrientation:( UIInterfaceOrientation)interfaceOrientation
{
return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );
}
to provide landscape orientation for the matchmakerViewController. It works perfectly on iPhone and even on iPad simulator but not on iPad device. When i run the application on iPad matchmakerViewController misteriously appear in the portrait orientation. What's wrong? How do i fix it? Thanks
Change your shouldAutorotateToInterfaceOrientation like
-(BOOL)shouldAutorotateToInterfaceOrientation:( UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Also check your application plist file, there will be a key like Supported Interface Orientations it's type will be array and will have 4 values. Delete the portrait modes from the plist and save it.
It will work. Please check this.
(This is most likely not your problem, but I use the following code and it works fine)
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight)
Additionally, make sure the parent view is set to autorotate true. shouldAutorotateToInterfaceOrientation doesn't work
Here is the elegant solution through Categories, extend the GKMatchMakerViewController, the same solution will work on any other game center view such as leader board views and achievement views:
.h file
#import <Foundation/Foundation.h>
#import "GameKit/GameKit.h"
#interface GKMatchmakerViewController(LandscapeOnly)
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;
#end
.m file
#import "GKMatchmakerViewController-Landscape.h"
#implementation GKMatchmakerViewController(LandscapeOnly)
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
#end
Let me know if it works!!
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
also check parent controller maybe some controller return YES
or try
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (interfaceOrientation==UIInterfaceOrientationPortrait)
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
else
return NO;
}