I am developing a iPad application which always shows in Landscape mode.
in iOS5, I was using 'shouldAutorotateToInterfaceOrientation' to return the value as 'YES' and I also configured the info.plist to support only the landscape mode. All goes well.
In iOS 6, I am aware that the method 'shouldAutorotateToInterfaceOrientation' is deprecated. I went thru lot of discussions in the net and tried all suggested solutions but the results are still zero (Meaning, iOS6 simulator shows in portrait mode.
My code is given below…. Any advise is very much appreciated…
In the AppDelicate.m
MyTestUI *myTest = [[MyTestUI alloc] init];
navigationController = [[UINavigationController alloc] initWithRootViewController:myTest];
[navigationController setNavigationBarHidden:YES];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
[myTest release];
return YES;
in the MyTestUI.m
- (BOOL)shouldAutorotate {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait) {
}
return YES;
}
**// iOS 5.1 Fix is below**
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
In AppDelegate.m
Instead of
[self.window addSubview:navigationController.view];
use this one:
[self.window setRootViewController:navigationController];
Hope this helps.
If you want your app to always be in landscape simply select landscape in the summary in xcode.
Your app is now locked to landscape
Ok, orientation since iOS 6 is handled from top to bottom :
supported orientation in the summary in XCode : if ALL your screens support the same orientation, then just use this one as it is the simplest.
If you handle different orientation rules depending on the screen of your application, then you want to use shouldAutorotate and supportedInterfaceOrientation methods for each UIViewController. (but do note that UINavigationController orientation doesn't depend on its top viewController - as opposed to what you might expect, so you could have to subclass UINavigationController to handle that correctly :
In MytestUI :
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
and in your UINavigationControllersubclass
- (BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
Related
I want to display the video in landscape mode only when video is playing in fullscreen using MPMoviePlayerController in ios6. My application supports only portrait mode.
Can anybody please suggest me, how can i do this?
Thanks.
I got the answer from below link
iOS 6 MPMoviePlayerViewController and presentMoviePlayerViewControllerAnimated Rotation
Make changes in application delegate file as fllows and its working:
Only change the UIview name as MPSwipableView in ios6
- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([[self.window.subviews.lastObject class].description isEqualToString:#"MPSwipableView"]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else {
return UIInterfaceOrientationMaskPortrait;
}
}
In your viewController, implement this method,
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape
}
I'm integrating Everyplay with my Cocos2d Game.My game only support Landscape orientation.
Everything goes well on iPad.
But When i test on iPhone(iOS6),it throws exception as following when I call "[[Everyplay sharedInstance] showEveryplay]":
reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'
I know orientation mechanism changed in iOS6.So i add this method:
-(BOOL)shouldAutorotate{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
Then "[[Everyplay sharedInstance] showEveryplay]" works without exception, but my game also support Portrait orientation that I do not want to.
How can I do if I only want to support Landscape in My Game, but let "[[Everyplay sharedInstance] showEveryplay]" works without exception?
You have two options how to fix the problem.
Option 1:
Add UISupportedInterfaceOrientations array into your game's info.plist with items UIInterfaceOrientationPortrait, UIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight and UIInterfaceOrientationPortraitUpsideDown. You can easily do this from xCode by checking all Supported Interface Orientations from your project summary page or by editing the info.plist file manually.
Option 2:
Add the following method to your application's AppDelegate.m file:
// IOS 6
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAll;
}
In both cases you must also make sure that you have added the landscape only orientation handling code to your game's main UIViewController.
// IOS 5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
// IOS 6
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
On iPhone Everyplay webview is always on portrait mode, but on iPad the webview supports both. Recording supports both modes as does the video player. We will likely in near future update the landscape mode for iPhone resolution too, but it will require some redesign before this task is complete.
I am searching the whole net for days, but can't find an answer.
The problem is: I can't force my app to present ALL UIViewControllers just in portrait mode, except one UIViewController, which should be able to work in every of the 4 modes.
Those are my options:
iOS 6
UINavigationController
UITabBarController
Storyboard
All modes are enabled in the project (also in Info.plist)
I already tried
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
but it does not even seem to work..
Any idea?
Found the answer:
Subclass UINavigationController (https://stackoverflow.com/a/12999017/1011125) OR UITabBarController if used.
Set up the orientations (https://stackoverflow.com/a/12539784/1011125).
That's it :).
I have to write an universal app, the iPhone part has only to be presented in Portrait so it would be the preferred orientation and it doesn't have to support other orientations, BUT I encountered the problem that adding a MPMoviePlayerController inside a modally presented controller it's ability have to rotate in Landscape.
For this if I block only in portrait the supported interface orientations in the app settings and in that controller I do:
- (BOOL) shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeRight;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
the result is a 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!' crash.
Otherwise if I have to set supported orientations Portrait and Landscape but everywhere block the preferred orientation and set shouldrotate to NO in every controller should work I suppose but it would be really a bad thing in my opinion.
How you will do with this kind of new interface orientation mechanism?
Thanks
I've been using Xcode 4.4 for my project for iOS and I wanted one of my screens to be permanently landscape so I used
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
and it worked just fine and since I updated to Xcode 4.5 and iOS 6.0 it didn't work at all so I found out that I have to use the new functions and now I have:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeRight;
}
- (BOOL)shouldAutorotate {
return YES;
}
so now my screen is landscape but the status bar remains in its place like the screen is still in portrait mode.
I don't know how to fix it.
Thank you.
I implemented this into the viewWillAppear function and it worked in iOS6:
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];