Prevent View that is accessed from a table view controller from auto rotating

66 views Asked by At

I have a view controller that i access through a table view controller that has a embedded to a navigation control. I would like my view controller to always be in portrait orientation. The view controller has a button that launches a video that i would like to be able to auto rotate or always be in landscape.

the following code works without the tableview controller, but when i put in the tableview, it stops working.

thanks in advance for any help.

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.[[UIDevice      currentDevice] beginGeneratingDeviceOrientationNotifications];



}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.

}

- (IBAction)play:(id)sender {

    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                         pathForResource:@"FINAL_De_Air_Purge_System"    ofType:@"mp4"]];
    MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc]
                                                     initWithContentURL:url];
    [self presentMoviePlayerViewControllerAnimated:playercontroller];
    playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    [playercontroller.moviePlayer play];
    playercontroller = nil;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

return UIInterfaceOrientationPortrait;

}

- (BOOL)shouldAutorotate {
return NO;
}
@end
1

There are 1 answers

0
TheCodingArt On

I believe if you follow the following, you should be good:

    -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

Should be in App delegate to

`- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}`

Should be in all ViewControllers you don't want to rotate

    - (BOOL)shouldAutorotate
{
    return YES;
}

Should be in your ViewController that pushes the movie player to let iOS know it's allowed to rotate

Once you push the movie player, it should know it can rotate and should work just fine. When popping/dismissing the movie player, the previous viewController should be rotated in portrait as wanted.