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;
}
Related
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 am using this code to lock the landscape mode for my iOS application.
#pragma mark Orientation handling
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationMaskAllButUpsideDown);
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
It is working fine in iPhone but it is not working correctly in iPad. It does not lock the landscape mode.
Need some guidance on this.
This code is incorrect:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationMaskAllButUpsideDown);
}
A UIInterfaceOrientation is not a UIInterfaceOrientationMask. Try something like this instead:
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
That being said, if you are trying to lock your application into landscape mode, there are multiple other issues here — for instance, your supportedInterfaceOrientations lists only portrait modes, not landscape!
Ideally just set it in the summary tab as the comment says. If you really want to do this in code, this is only available in whatever you set as the rootViewController in your AppDelegate class.
In iOS 6 I use:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
If you have a NavigationController you can add the method to a Category.
I use:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
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
}
}
I have an app that is a game, and it does not look or work right in Landscape.
Right now My code is:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
And that allows it only to run in portrait (home button on bottom) and I want it to run in both Portrait's (Home button on bottom OR top) so apple accepts it.
I have tried:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
and it didnt work...
Can someone give me the Code to make it so it runs in both portrait modes.
You can only return once, so the second return statement is never evaluated. Make it a boolean OR:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) || (interfaceOrientation == UIInterfaceOrientationPortrait);
}
There are also macros for portrait and landscape, but this should work just fine.
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);