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.
Related
I have an iOs project that needs to support all orientations on iPad and on iPhone I need to support only portrait on all view controllers EXCEPT one that needs to support all orientations and autorotate.
I tried:
#pragma mark - Should Rotate device
- (NSUInteger)supportedInterfaceOrientations
{
if ([[DeviceInfo sharedInstance] is_iPhone]) {
return UIInterfaceOrientationMaskPortrait;
} else {
return UIInterfaceOrientationMaskAll;
}
}
But that method doesn't get called...
How should I do this?
Why don't you select the wanted ones here:
Select your app in project navigator -> general -> select your target -> scroll down to deployment info.
If my understanding is right then I have given answer for this query so u could follow this link.
Do let me know if any doubt.
Okay so got solution for your iOS 7 as below method write down in appDelegate class.
- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if ([[[[[[UIApplication sharedApplication] keyWindow] rootViewController] childViewControllers] lastObject] isKindOfClass:[ViewController class]]) //Here you could provide your view controller and provide orientation which u want for that particular view controller.
{
return UIInterfaceOrientationMaskPortrait;
}
else
{
return UIInterfaceOrientationMaskLandscape;
}
}
This will help you out for iOS 7.
The problem was solved by implementing the methods on the navigation controller that owns all the views
I have an app that support only portrait mode, but I have an NowPlayingViewController with youtubeView.
I want only this youtubeView support landscape mode (when it's fullscreen)
I found this (in appdelegate.m)
- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([[self.window.subviews.lastObject class].description isEqualToString:#"<string>"]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else {
return UIInterfaceOrientationMaskPortrait;
}
}
but I don't know how to set description to my youtubeWiew with this string.
Anyone has solutions?
Rotation has become bit tricky as you can't rotate it forcefully. Though there is a solution, is you need to Customize UINavigationController to add Landscape Rotation, and then present the extra view as modal, it will work.
For more clarification see a sample here I have made for rotations.
I hope it will help you and others.
Cheers.
Before you vote this question down, note, that I've already tried to implement all the solutions available on stackoverflow. Here is the issue:
My application runs only in portrait mode. The only thing which needs to be in landscape is video player. When a user taps on my TableViewCell this block of code is called:
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:videoUrl];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
After that, I need to give the user the ability to watch video both in portrait and landscape mode. After he is done, everything should get back into portrait mode. I've tried to call this block of code in my AppDelegate.m:
- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
NSUInteger orientations = UIInterfaceOrientationMaskPortrait;
if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]]) {
orientations = UIInterfaceOrientationMaskAllButUpsideDown;
}
return orientations;
}
With it everything is fine except one thing - when the video is over or when the user taps "Done" button while in landscape mode, my view controller appears in landscape mode too.
Besides it, I've tried a lot of other methods - but nothing seems to work.
I'll be glad for any help!
Thanks #Shubham - Systematix for the answer.
All that I had to do was to remove every code related to autorotating except this method in AppDelegate:
- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if ([[window.rootViewController presentedViewController] isKindOfClass: [MPMoviePlayerViewController class]])
{
//NSLog(#"in if part");
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else
{
//NSLog(#"in else part");
return UIInterfaceOrientationMaskPortrait;
}
}
When I did it everything worked like a magic!
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];
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.