Question

I try a lot of things, but I still can't rotate only 1 viewControllor in all my app. I would like to show (or to rotate) in landscape only a vc with a MPMoviePlayerViewController.

Like the videos in Facebook app. The app is only in portrait but video could rotate. After played the video, application return in portrait mode. I'm able to ratate but after "done" videoplayer button clicked the view return in landscape mode.

How can I fix this?

Thank you very much.

Was it helpful?

Solution

  1. Create new View controller for Playing videos

  2. Click on Project then click on Target. In General category under Deployment Info enable All the rotations

  3. Now open your Root view controller and Put following lines.give what orientation of your app

code:

-(BOOL)shouldAutorotate
{
    return TRUE;
}

-(NSUInteger)supportedInterfaceOrientations
{
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    else
    {
        return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    }
}

4.Now if you used addsubview method to represent your other ViewController's views then no need to apply orintation methods to other controller. But If any vc you have used PresentController method then add orientation methods to that conroller

OTHER TIPS

Create a new UIViewController that you will use for showing a video.

Create a MPMoviePlayerController property

@property (nonatomic, strong) MPMoviePlayerController* moviePlayerController;

Then in viewDidLoad, try this:

 - (void)viewDidLoad
    {
        [super viewDidLoad];

        _moviePlayerController = [[MPMoviePlayerController alloc] init];
        _moviePlayerController.controlStyle = MPMovieControlStyleFullscreen;

        _moviePlayerController.contentURL = [NSURL URLWithString:@"example.com"];

        // Rotating the player to landscape position
        _moviePlayerController.view.frame = CGRectMake(0.0f,
                                            0.0f,
                                            [UIScreen mainScreen].bounds.size.height,
                                            [UIScreen mainScreen].bounds.size.width);

        _moviePlayerController.view.transform = CGAffineTransformMakeRotation(M_PI_2);
        _moviePlayerController.view.center = self.view.center;

        UIView *playerView = _moviePlayerController.view;


        [self.view insertSubview:playerView atIndex:0];
        [_moviePlayerController prepareToPlay];
    }

Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top