how to provide only one view with landscape for MP

2020-02-15 15:06发布

i had spend 2 hours finding the correct code to fix my orientation problem this are my movieplayer code. i need this particular view to be shown in landscape.

in appdelegate i set all orientation and in my rootviewcontroller i set is as portrait only and in my movieplayer view as landscape but not luck. can anybody give me some comment on how to fix the issues please ?

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

my rootviewcontroller

- (BOOL)shouldAutorotate
{
    return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}


-(void)prepareIntroVideo
{
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"designthinking_pt1" ofType:@"mp4"]];
    self.playercontroller = [[MPMoviePlayerController alloc] initWithContentURL:url];
    [self.playercontroller.view setFrame:CGRectMake(0, -20, 320, 480)];
    self.playercontroller.movieSourceType = MPMovieSourceTypeFile;
    self.playercontroller.scalingMode = MPMovieScalingModeAspectFill;
    self.playercontroller.fullscreen = NO;
       self.playercontroller.controlStyle = MPMovieControlStyleFullscreen;
    //playercontroller.controlStyle = MPMovieControlStyleFullscreen;
    self.playercontroller.view.userInteractionEnabled =YES;
    self.playercontroller.view.backgroundColor = [UIColor blackColor];
    self.playercontroller.shouldAutoplay = NO;

    //playercontroller.repeatMode = YES;
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlaybackComplete:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:self.playercontroller];


    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(applicationDidEnterBackground)
                                                 name: UIApplicationDidEnterBackgroundNotification
                                               object:[UIApplication sharedApplication]];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(applicationWillEnterForeground)
                                                 name:UIApplicationWillEnterForegroundNotification
                                               object:[UIApplication sharedApplication]];


    [self.playercontroller prepareToPlay];
    [self.view addSubview:self.playercontroller.view];
    [self.playercontroller setFullscreen:YES animated:YES];


    //[self.playercontroller stop];
    [self.view sendSubviewToBack:self.playercontroller.view];

}

- (BOOL)shouldAutorotate
{
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationLandscapeLeft;
}

2条回答
冷血范
2楼-- · 2020-02-15 15:42

I would look into preferredInterfaceOrientationForPresentation, I spent about a week on this problem a few months ago. I don't remember exactly how i solved it but I do know it had something to do with implementing that method

查看更多
来,给爷笑一个
3楼-- · 2020-02-15 15:55

You can check my example... https://dl.dropboxusercontent.com/u/19438780/testRotate.zip

I have 2 controllers with navigation controller - portrait; for this I "subclassed" nav controller (here is the "rotation" code for portrait)

The 3th controller is landscape - must be presented modal if you want to rotate it - put the rotation code accordingly .

查看更多
登录 后发表回答