Xcode 4.5 SplitView broken orientation with iOS 5.1 (working on iOS6 thought) - orientation

I was working on a splitView project when the Xcode was updated to v4.5. Since then autorotation was working perfectly. After the update, autorotation works only for iOS 6. On iOS 5.1 i am stack in Portrait. I have read all possible solutions but nothing seems to be able to fix my problem. Below is what i have done so far:
Checked that All orientations are in my plist.
Replaced (BOOL)shouldAutorotateToInterfaceOrientation:
with
- (BOOL)shouldAutorotate
{
return TRUE;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
I added the below snippet in the app delegate
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return (UIInterfaceOrientationMaskAll);
}
I show in another answer the below snippet how ever i am not sure how to implement it in a splitView controller
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
window.rootViewController = topLevelViewController;
...
}
Can anybody help me out with this?

You need to keep the method from iOS 5:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
to continue support for iOS 5. You thus, keep both the new ones for iOS 6 and the old ones for iOS 5. Note that for the UISplitView to rotate in iOS 5 all the enclosed view controllers have to have the above method.

Related

Lock App into one specific orientation in Cocos2D v3

I am trying to disable screen rotation in cocos2d-3.x, but I cannot figure out how. I have the following code in CCAppDelegate:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
setupCocos2dWithOptions:
[self setupCocos2dWithOptions:#{
CCSetupShowDebugStats: #(YES),
// Run in portrait mode.
CCSetupScreenOrientation: CCScreenOrientationPortrait,
}];
return YES;
}
The screen is in portrait mode, but it also rotates to portrait UpsideDown. I read that Cocos2d uses a UIViewController so should I use an apple method for this?
Cocos2D currently only allows to choose between "Landscape" or "Portrait" but doesn't allow to specify the orientation more specific. This likely will be fixed in Cocos2D but for now you can modify the Cocos2D source code as a workaround. I have opened a GitHub Issue for this problem.
Implementing supportedInterfaceOrientations in CCAppDelegate does not fix the issue because the method is implemented by the CCNavigationController and that overrides your settings.
Open "CCAppDelegate.m" and go to line 77. You should see this method:
-(NSUInteger)supportedInterfaceOrientations
{
if ([_screenOrientation isEqual:CCScreenOrientationAll])
{
return UIInterfaceOrientationMaskAll;
}
else if ([_screenOrientation isEqual:CCScreenOrientationPortrait])
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
else
{
return UIInterfaceOrientationMaskLandscape;
}
}
You can change the entire method to only support one orientation, e.g.:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationPortrait;
}
When you change that method you can return one of the 4 orientations you want to lock your game into:
UIInterfaceOrientationMaskLandscapeLeft
UIInterfaceOrientationMaskLandscapeRight
UIInterfaceOrientationMaskPortrait
UIInterfaceOrientationMaskPortraitUpsideDown
That's the workaround for now.

Control autorotation from a view controller without modifying the rest of the app

I'm developing an iOS framework. It contains a view controller that can be displayed modally by the app that will be using my framework. I don't have access to the app code, just my framework. I'd like to prevent autorotation when my view controller is being displayed. Can this be done? I've tried returning NO from shouldAutorotateToInterfaceOrientation: in my VC, but that doesn't get called.
You could add this code to your AppDelegate. It will allow other viewControllers to respond to autorotation calls.
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
/* This is in order to allow views that do not support landscape mode to be able to load in
*/
return UIInterfaceOrientationMaskAll;
}
Also, in iOS 6.0 and later the shouldAutorotateToInterfaceOrientation: method has been deprecated. It could be substituted by the following methods:
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortrait;
}
- (BOOL) shouldAutorotate{
return YES;
}

UIinterface orientation ios6

My code is working fine in iOS 5.1 but not in iOS 6. I am getting orientation problems.
I am using this code for controlling the orientations
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}
I want to show one view controller in Landscape mode and other viewController in Portrait mode
Any one can help me with this?
Thanks
Try look at this
iOS 6 Tips and Tricks Upgrading Your Apps
OR
try to add this codes in Main viewcontroller:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeRight;
}
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)w {
return (NSUInteger)[application supportedInterfaceOrientationsForWindow:w] | (1<<UIInterfaceOrientationPortrait);
}
And main viewcontroller must be added how:
[window setRootViewController: mainController];
instead
[window addSubview: mainController.view];

iOS 6 MPMoviePlayerViewController and presentMoviePlayerViewControllerAnimated Rotation

In previous iOS versions, our video would rotate automatically but in iOS 6 this is no longer the case. I know that the presentMoviePlayerViewControllerAnimated was designed to do that before but how can I tell the MPMoviePlayerViewController to rotate automatically?
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
In appdelegate.m :
- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if ([[self.window.subviews.lastObject class].description isEqualToString:#"MPMovieView"]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else {
return UIInterfaceOrientationMaskPortrait;
}
}
Kinda a hack, but works well...
I just ran into the same problem. James Chen's solution is correct, but I ended up doing something a little simpler that also works - overriding application:supportedInterfaceOrientationsForWindow in my app delegate and returning allButUpsideDown if my rootView controller was modally presenting an MPMoviePlayerViewController. Admittedly a hack, and may not be appropriate to all situations, but saved me having to change all my view controllers:
- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return [rootViewController.modalViewController isKindOfClass:MPMoviePlayerViewController.class ] ? UIInterfaceOrientationMaskAll : UIInterfaceOrientationMaskAllButUpsideDown;
}
This is not limited to MPMoviePlayerViewController. From iOS 6 the autorotation has been changed. see Autorotate in iOS 6 has strange behaviour .
To make your app behave as pre-iOS 6, you have to make the app support all orientations (edit UISupportedInterfaceOrientations in plist), then for all other view controllers which don't support rotation, override this method to return NO:
- (BOOL)shouldAutorotate {
return NO;
}
By default MPMoviePlayerViewController supports all orientations so this should be enough to make it work.

iOS 6 autorotation in simulator varies from actual iOS 6 device

My app will not autorotate in the iOS 6 GM simulator but it does with the same version of iOS on the device. Could this be a simulator bug? The app is using deprecated autorotation methods, but they are working fine on the device itself which makes me wonder if the simulator APIs are different?
It should still work with the deprecated rotate methods, but you need to add the following to your didFinishLaunchingWithOptions: method:
self.window.rootViewController = yourRootViewController;
This tells the main window what view controller to send the rotate notifications to. This is new with the iOS 6.0 SDK.
This is what I added to get my app working again:
// Tell the system what we support
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
// Tell the system It should autorotate
- (BOOL) shouldAutorotate {
return YES;
}
// Tell the system which initial orientation we want to have
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
Adding the following was not enough to make it work on the simulator:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
- (BOOL) shouldAutorotate {
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
To make it work, I also added the following inside the didFinishLaunchingWithOptions function of the appDelegate class:
self.window.rootViewController = viewController;
I stopped getting the following error after this addition:
Application windows are expected to have a root view controller at the end of application launch
- (BOOL)shouldAutorotate {
return NO;
}
and set the supported rotations for the root view controller in the app plist file to only portrait.

Resources