Portrait app. Landscape video. shouldAutoRotate not running - ios

I have a really annoying problem that I've been fighting with for hours now. I have an app that runs in portrait only, but when I play video I want that to playback in landscape.
From what I've read the way around this is to change the Info.plist to allow landscape right, left and portrait, then to go through all the viewControllers and put in the following code
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
//ios4 and ios5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
The problem is that it appears that this isn't getting called at all as free rotation is still allowed when running the app.
Can anyone think of something that could possibly be causing this problem?
I don't know if it's worth mentioning, but I am running the latest beta of xcode 5 and running ios 7 on my iPhone 5.
Thanks a lot.
Luke

I had a similar problem. In my case, I wanted all my app to be in Portrait, except 1 UINavigationController. This is how I solved it:
I have an App with a UItabBarController as root. Each of my 5 tabs are embedded in a UINavigationController… and that seems to be the problem. So, what I did was
1- You have to allow all "Device Orientations" in your "Deployment Info"
2- I created a custom class for my UITabBarController.
3- In the .m of that I added the following code:
- (BOOL)shouldAutorotate {
return YES;}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait; }
4- Then, in the UIViewController I wanted to be different I added the following code in .m:
- (BOOL)shouldAutorotate {
return YES; }
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll; }
Et voilĂ  !
Hope this helps.
Konrad

Related

Storyboard ignores UIInterfaceOrientation settings

I have a strange problem with UIInterfaceOrientation. In my project there are many different views, some of them should rotate in landscape mode, and some of them should not. The problem is that all the view which were not created using Storyboard and in which only the UIInterfaceOrientation portrait is enabled this works fine and the view does not rotate, instead all the views created using the Storyboard, even if the UIInterfaceOrientation landscape mode was disabled they keep rotating. In my Xcode project setting those checks are enabled and I cannot change them:
How can I completely disable the device rotation in all the different views? [Storyboard or not].
This is the code I use to disable the device orientation in all the storyboard view controller, but it does not work:
- (BOOL)shouldAutorotate {
return NO;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Try this code maybe it will work for you.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientationMask)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationMaskPortrait);
}
The solution was to assign a UINavigationController class to the UINavigationController in the Storyboard file and to place this code in his .m file:
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}
Please, check if in your project .plist there are more than one item for orientation or something strange. I sometimes have found that orientation has different values in plist or duplicated keys.
Hope it helps

How to show MPMoviePlayerController in landscape mode

i am working on a app where I am required to show "MPMoviePlayerController" in landscape mode and portrait mode. But My whole app is required to support Portrait mode only. That is no landscape mode for any view other than for the "MPMoviePlayerController".
I tried few things given over stack overflow. Nothing worked in my case. Feels Stuck in the middle. But I have seen some of the app supporting suck kind of requirements.
I have to implement it for both iOS 6, 7
In my app am using "XCDYouTubeVideoPlayerViewController" for playing videos(playing the youtube videos)
Please Help
I had the same issue, and the following solved the problem:
First you need to allow the Landscape mode either, by checking the checkboxes at Target / General / Deployment Info / Device orientation, and then you have to disable Landscape orientation by code at every ViewController you use in your app.
#pragma mark - Set Supported Device Orientation
//For iOS6
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
//For iOS4 and iOS5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
But don't disable landscape orientation for the XCYoutubeVideoPlayerViewController, so at fullscreen it can rotate to landscape.
I have another solution for this, It will work for all MPMoviePlayerController, below is my code
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)windowx
{
if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]] ||
[[self.window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(#"MPInlineVideoFullscreenViewController")])
{
if ([self.window.rootViewController presentedViewController].isBeingDismissed)
{
return UIInterfaceOrientationMaskPortrait;
}
else
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
}
else
{
return UIInterfaceOrientationMaskPortrait;
}
}
What we basically do here is we enable Landscape orientation for all MPMoviePlayerController classes which are actually MPInlineVideoFullscreenViewController when you present it for fullscreen.
Hope this helps

iOS 7 unlock device orientation in video playback

My entire app is locked in portrait orientation but when a video is played I wanna allow all orientations just for the video playback.
Storyboard:
TabBarController --> NavigationController --> MyVideosController --> MyVideoPlayerController
This is one of many I've tried:
Allow One View to Support Multiple Orientations While Others Do Not iPhone
The problem is that I never even reach into this method in my MyVideoPlayerController.m:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
In my experience just about every suggestion you will find on here won't work for you. What you are going to want to do is (if you are using storyboards) add another navigation controller and a view controller. You will push the 2nd navigation controller modally and lock it to the orientation you desire. This way your video player can "pop up" and be in the orientation(s) you want.
Its really annoying.
An alternative (which I don't really suggest) is that you can turn on AutoLayout and perhaps try the IOS6 version.
For iOS-6 , I have done this , it is running greatly
(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;
}
(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
try this code, add it to your class it's working for me:
#pragma mark - Orientation
- (BOOL)shouldAutorotate {
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

iPad 1 showing portrait mode instead of Landscape

I have an application on AppStore that has portrait Mode on iPhone and on iPad it works on landscape. However i am getting reports that it shows portrait on iPad 1 thus destroyed overall View.
Why is iPad 1 specifically showing Portrait mode?
The version of iPad is 5.1.1
In ios 6, the methods for supporting interface orientation has been changed. For supporting both interface orientation in both version, we need to check the os version and write code acoordingly.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Support for new versions
- (NSUInteger)supportedInterfaceOrientations {
}
- (BOOL)shouldAutorotate {
}
In my View Controller i have the following:
- (NSUInteger)supportedInterfaceOrientations {
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
}
- (BOOL)shouldAutorotate {
}
Go and make sure ALL view controllers return the correct orientation modes they support. I've seen such behaviour in iOS 5 and if I recall correctly that was the reason.
I had a very similar from and I resolved it by changing the following code in AppDelegate.m-> applicationDidFinishLaunching:
[self.window addSubview:self.viewController];
to
[self.window setRootViewController:self.viewController];

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