1

I have an app whose rotation configuration is defined dynamically, therefore I cannot set the supported rotations in the project file.

Therefore I have to handle the new shouldRotate methods (thanks Apple!!)

But despite having overriden these and prevented the full UI from displaying in anything but portrait. When a video view is displayed fullscreen and rotated. The video will rotate to landscape still.

Is there another way to preview the video specifically from rotating at all?

Anthony Main
  • 6,039
  • 12
  • 64
  • 89
  • 1
    Which video class are you using? Can you post your code regarding the `shouldRotate` methods? – abellina Mar 20 '13 at 13:26
  • MPMoviePlayerController - with regards the should rotate code, assume that Im returning NO, as thats always the result in this case – Anthony Main Mar 20 '13 at 13:40
  • I haven't tried this, but I believe you want the MPMoviePlayerViewController instead. http://stackoverflow.com/questions/3019200/how-to-rotate-an-mpmovieplayercontroller – abellina Mar 20 '13 at 13:42
  • I think Ive found that my problem is caused because my video view is added to the Window not the VC and therefore it is not respecting the shouldAutorotate methods of the VC, does the Window have rotation methods? – Anthony Main Mar 20 '13 at 17:01
  • Logic tells me that if the view controller isn't pushed somewhere that the rotation events won't propagate to it. Check out this other answer which seems to deal with the specific problem of rotation of a `UIView` inside of a `UIWindow`, by using notifications: http://stackoverflow.com/questions/2508630/orientation-in-a-uiview-added-to-a-uiwindow – abellina Mar 20 '13 at 17:17

1 Answers1

0

Here's an implementation using a MPMoviePlayerViewController subclass supporting portrait and portrait upside down (but you can easily change the mask). This works in iOS 6 as you suggested, prior versions have different rotation selectors.

Usage:

NSURL* url = [NSURL URLWithString:@"your_movie"];
MovieViewController* mvc = [[MovieViewController alloc] initWithContentURL:url];

// I did this from the app delegate. 
// You could push this view controller, present it modally, etc.

[self.window setRootViewController:mvc];

In MovieViewController.h:

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>

@interface MovieViewController : MPMoviePlayerViewController

- (id)initWithContentURL: (NSURL*) url;

@end

In MovieViewController.m:

#import "MovieViewController.h"
#import <MediaPlayer/MediaPlayer.h>

@interface MovieViewController ()

@end

@implementation MovieViewController

- (id)initWithContentURL: (NSURL*) url
{
    self = [super initWithContentURL: url];
    if (self) {
        // Custom initialization


    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
    ROTATION CODE
 */
- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}


@end

Result (note rotation is enabled on the project for all rotations..):

enter image description here

abellina
  • 1,016
  • 1
  • 11
  • 27
  • This is a suitable answer to the question, it doesnt solve my particular problem, but will be a better answer for most people – Anthony Main Mar 20 '13 at 17:01