iOS App: Window rotation always Portrait instead of Landscape - ios

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]

Related

How to set the Orientation of iPhone App in UIDeviceOrientationIsPortrait?

I am develop a IOS Application, I use the following code for lock the orientation of App.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
If the orientation is UIInterfaceOrientationPortrait When start the App. It will lock the orientation to UIInterfaceOrientationPortrait.
But the view still show Landscape , when start the App in Landscape.
How to set the Orientation of App to UIDeviceOrientationIsPortrait for App start whether the phone is Landscape or 'Portrait`?
If you need to lock the whole app to Portrait then go to TARGETS -> General Tab -> Deployment Info
This will lock the whole app to Portrait Mode
If you only need one orientation for the entire app then go to targets, General, and deployment info. Then check portrait.
I use the following code for setting Orientation to Portrait.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated] ;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
//set the orientation is Portrait when the App start.
if ([[UIDevice currentDevice] respondsToSelector:#selector(setOrientation:)]) {
objc_msgSend([UIDevice currentDevice], #selector(setOrientation:), UIInterfaceOrientationPortrait );
}
}

i designed my nib in land scape mode, but in simulator it is showing in portrait mode?

i designed my nib in land scape mode with buttons and images, but in simulator it is showing in landscape mode but the button and images are not as it looks on the nib, they appear to be on right hand side instead of on top? any pointers please.
nib image
If you want this view controller to be limited to a certain orientation use in your view controller class
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
please read my answer here Keep iPhone rotation in landscape?
How you design the view (portrait/landscape) in interface builder has no influence over how it will actually be shown. You need to set that in code (or possibly in a p-list).
Use this code
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
NSLog(#"Landscape Mode");
// your code when your sdk is in landscape mode
}
else
{
NSLog(#"Portrait Mode");
// your code here
}
}

GameCenter landscape orientation doesn't work on iPad

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;
}

How to set the orientation of the app in ios automatically

I set the initial orientation of the app to UIInterfaceOrientationLandscapeRight, but when I open the app with the physical orientation of UIInterfaceOrientationLandscapeLeft, it will show the interface of UIInterfaceOrientationLandscapeRight first, then rotate to the UIInterfaceOrientationLandscapeLeft orientation.
How to make it open with the same orientation as the device?
You have to instruct your UIViewController instances on which interface orientations are supported by implementing "shouldAutorotateToInterfaceOrientation" as follows:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
return YES;
} else {
return NO;
}
}

iPad Orientation Question - One Orientation or All four - can't just get two to work

I've got an iPad app that I absolutely need to have in just landscape, I know the situation on the suggestions but for this app it needs to be landscape.
Now here's my problem.
I have editted my .plist file to support both landscape left and landscape right in the appropriate manner and have put an autorotate snippet into my code, however if I have this
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
/*if (autorotateOrientation && tapViewOrientation != interfaceOrientation && !insecureKeyboardWarningDialog) {
tapViewOrientation = interfaceOrientation;
[[NSUserDefaults standardUserDefaults] setInteger:tapViewOrientation forKey:kDefaultKeyTapViewOrientation];
*/
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
[self prepareTapView];
// return NO;
}
I get only landscape left (obviously)
if I have this
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
/*if (autorotateOrientation && tapViewOrientation != interfaceOrientation && !insecureKeyboardWarningDialog) {
tapViewOrientation = interfaceOrientation;
[[NSUserDefaults standardUserDefaults] setInteger:tapViewOrientation forKey:kDefaultKeyTapViewOrientation];
*/
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight);
[self prepareTapView];
// return NO;
}
I get all four orientations. Now I could just come upw tih an option for the portrait orientations however truth be told it would be ugly and non functional hence my desire to work for landscape only in this particular instance.
Can anyone suggest what I'm doing wrong and how to limit myself to landscape only, but both forms of landscape?
return UIInterfaceOrientationIsLandscape(interfaceOrientation);

Resources