upSideDown iPhone orientation is not working in iOS 6? - objective-c

hope you will be fine and doing your best.
I am getting a problem in upSideDown Orientation in my iOS 6, while I think I am doing everything perfect, but I don't know why it is not working for me. I am sharing my problem with you so to get any solutions.
What I have done so far:
a) In xcode project Summary tab, I have enabled all the 4 orientations.
b) I have added piece of code (written below) in all of my controller classes.
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
but still the upSideDown Orientation is not working
Thanks in anticipation.

I have found its solution.
We need to make a separate class of UINavigation Controller type. In .m file add the following methods
// Deprecated in iOS6, still needed for iOS5 support.
// ---
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
// return (interfaceOrientation == UIInterfaceOrientationPortrait);
return YES;
}
// iOS6 support
// ---
- (BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll;
}
Now assign this newly created class to your Navigation Controller in story board. Also add the .m file of this class in 'Project -> Build Setting -> Compile Sources'. Run the project and it will support and perform all the orientations including upSideDown.
I hope it will help you all.
Regards

Related

iOS 6 Game Center Crash on Authentication in landscape mode cocos2d

I have developed a game in cocos2d and all game screens are in Landscape mode. I am trying to implement game Center but getting crash on authentication. I did not find answer of similar type of issues. please suggest right approach...
Crash issue:-'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'
I tried below solution but it also disturb game orientations, game starts work in portrait mode also, that i don't want:-
(NSUInteger)application:(UIApplication*)application
supportedInterfaceOrientationsForWindow: (UIWindow*)window
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
Make sure you selected landscape in Xcode summary page.
Also add these code in your viewcontroller
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
Update this function in AppDelegate:
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
return UIInterfaceOrientationMaskLandscape;
}
the solution for that is short, i spent a lot of time before finding it:
in the AppDelegate in the method didFinishLaunchingWithOptions put this line:
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
obviously before call the login game center method, i put that before create the UIWindows

iOS6 autorotation confusion and support for iOS5

Since iOS6, I realize that the shouldAutorotateToInterfaceOrientation: method has been deprecated. Most of my app I would like the user to be able to rotate, which does work in iOS6 and 5 currently. But, I have a modal view that I ONLY want to be portrait, so I have added the following without it actually working (tested in simulator and device):
// Tell the system what we support
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationPortrait;
}
// Tell the system It should autorotate
- (BOOL) shouldAutorotate {
return NO;
}
// Tell the system which initial orientation we want to have
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
Why isn't this code preventing my modal from rotating?
How can I still support the iOS5 method as well as the iOS6 methods without crashing for users on iOS5?
You have to embed the presented vc in a navigation controller where you can set the preferred orientation.
https://stackoverflow.com/a/12522119
You missed to but this line inside your -(void)viewDidLoad method
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"UIApplicationSupportedInterfaceOrientationsIsEnabled"];
I hope this can help you

iOS 6 UIInterfacePortrait ONLY viewcontroller being presented & stuck in landscape... when coming back from a landscape viewcontroller in nav stack

So like many others, I ran into the problem of only having one or two viewcontrollers support both portrait and landscape interface orientations, in an otherwise portrait only app. Everything worked fine prior to iOS 6, but suddenly autorotating stopped working. Thanks to some great questions here, I was able to resolve that issue by having the initial navController return the individual topViewController's preference for shouldAutorotate via:
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
However, I have stumbled onto a new problem. the root vc (viewController A) should NOT autorotate and should only support portrait. ViewController B in the nav stack supports portrait and landscape. If I am in viewController B, and am in landscape, and touch "back" to pop the view back to viewController A... vc A loads in landscape, which it is not supposed to even support, and wont rotate back to portrait because shouldAutorotate for vc A is set to NO...
Any ideas on how to deal with this would be greatly appreciated. My initial thought was to override vc B's "back" button with a manual method that first force rotates back to portrait if the view is in landscape... then pops the viewcontroller back to vc A... but I cant figure out how to force a rotation programatically. Any ideas?
here are the interface methods in vc A:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return NO;
}
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
and here is what they are in vc B:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
In vcA set
-(BOOL)shouldAutorotate
{
return YES;
}
But keep
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationPortrait;
}
Then the view will rotate back to the (only) supported orientation when you return from vcB
The problem is that all container view controllers (Tab Bar Controller, Navigation Controller etc.) support all those interface orientations that you give in your plist file. When the system asks for the supported interface orientations the root view controller's settings and method implementations override it's children's.
In this case the Navigation Controller supports both landscape and portrait and when the B View controller pops, although the system asks for A's interface orientations, it will ask it's root view controller too and that will be the "winner" and since the Navigation Controller supports landscape, it stays in landscape despite that A supports portrait only.
One solution is, that you subclass the root view controller and change it's rotation methods dynamically as needed. When only portait is needed your root's implementation should return portait only and when both orientations are available, then your root should return both.

Supporting different orientations in iOS 6.0 for different view controllers

I am having custom split view controller in my App with a master controller and a detailed controller.
- (id)initWithMasterController:(UIViewController*)aMasterController
detailedController:(UIViewController*)aDetailedController;
The controllers provided for the master controller and details controller are UINavigationController.
As part of my app, there are two possible cases for orientation handling:
When six combination of controllers are used in master and details controller, all the orientations are supported for the app.
When there is a StudentDetailsViewController at the details controller alone, only two possible orientations can be supported. (Landscape)
When ever the device's orientation is changed, the below things happen in versions below iOS 6.0
The -shouldAutorotateToInterfaceOrientation: method gets called. The implementation of that method is below: At run time, I forward the request to master controller and details controller with the same call.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
BOOL res = [masterController shouldAutorotateToInterfaceOrientation:interfaceOrientation]
&& [detailedController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
return res;
}
The masterController's -shouldAutorotateToInterfaceOrientation will return TRUE. The implementation of the method in StudentViewController is below.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (IS_IPAD) ? UIInterfaceOrientationIsLandscape(interfaceOrientation)
: UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
The ability to get information on the new orientation to be changed helps me to decide if rotation should be enabled or not.
With iOS 6.0:
When ever the device's orientation is changed, the below things happen in versions of iOS 6.0
The method -shouldAutorotate of the split view controller gets called. Its implementation is below
- (BOOL)shouldAutorotate {
BOOL res = [masterController shouldAutorotate]
&& [detailedController shouldAutorotate];
return res;
}
The detailedController's shouldAutorotate calls the navigationController. The implementation of autorotate feature in StudentsController:
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return (UIInterfaceOrientationMaskLandscapeLeft
| UIInterfaceOrientationMaskLandscapeRight);
}
But with iOS 6.0, I am unable to control the orientation. Even though the supportedInterfaceOrientations method gets called, when the shouldAutorotate method of the StudentsDetailsController gets called, from the detailsController's shouldAutorotatemethod, the shouldAutorotateMethod does not obey the options mentioned in the supportedInterfaceOrientations method.
UPDATE:
I read the docs and the below notes are provided in the document.
sometimes you may want to dynamically disable automatic rotation. For
example, you might do this when you want to suppress rotation
completely for a short period of time. You must temporarily disable
orientation changes you want to manually control the position of the
status bar (such as when you call the
setStatusBarOrientation:animated: method).
If you want to temporarily disable automatic rotation, avoid
manipulating the orientation masks to do this. Instead, override the
shouldAutorotate method on the topmost view controller. This method is
called before performing any autorotation. If it returns NO, then the
rotation is suppressed.
Is it possible to temporarily disable automatic rotation based on the current orientation?
I believe this is some type of issue in iOS where the rootViewController does not consult the childViewController for their preferred orientation. However, you should try something like the following :
if (self.interfaceOrientation != UIInterfaceOrientationPortrait)
{
[[UIDevice currentDevice] performSelector:NSSelectorFromString(#"setOrientation:") withObject:(id)UIInterfaceOrientationPortrait];
}
to change the orientation back to portrait for a given view.
In your application delegate class define the following method, this method gets called before any other rotation methods in application.
Create a flag(isRotationEnabled) which will decide orientation of your app.
- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return self.isRotationEnabled ?
UIInterfaceOrientationMaskAll :
UIInterfaceOrientationMaskPortrait;
}
Change this flag based on different conditions in you app using the following code
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.isRotationEnabled = NO;

Set different supportedInterfaceOrientations for different UIViewControllers

So, as by the question, I use the following code to set userinterfaceOrientation for the viewcontroller.
- (BOOL) shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
I tried setting UIInterfaceOrientationMaskAll for another viewController.
Prior, I checked all the items for Supported interface orientations in the info-plist. Both the viewControllers returned true(as set in the info-plist) for all the orientations and didn't obey the above code. IT worked even in the absence of the above code. Is there anyway to restrict certain Supported interface orientations for particular classes? I made it working for the pre - iOS6 versions by following this link.
I was able to accomplish this by placing my supported orientation logic in a custom UINavigationController. I then segue to the relevant view controller.
#implementation PortraitNavigationController
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
...
I'd say implement your shouldAutorotateToInterfaceOrientation: on every view controller to make it return only YES for those orientations you wish to support.