在iOS中完成视频时更改方向

时间:2016-05-25 23:38:53

标签: ios objective-c uiinterfaceorientation

我认为我在完成按钮上的编码无法正常工作,因为我在视频开始时更改了我的屏幕方向,当视频完成时,我需要回到我的正常方向,我的编码就是。

vid = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
//[self presentModalViewController:vid animated:YES];
[self presentMoviePlayerViewControllerAnimated:vid];

NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(donebutton) name:MPMoviePlayerDidExitFullscreenNotification object:vid];

然后编码完成按钮方法

-(void) donebutton{
     NSLog(@"done");
     NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}

1 个答案:

答案 0 :(得分:0)

希望此代码可以帮助您在视频播放完成后更改设备方向。

-(void)playVideo {
      moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];

            [[NSNotificationCenter defaultCenter]
             addObserver:self
             selector:@selector(moviePlayBackDidFinish:)
             name:MPMoviePlayerPlaybackDidFinishNotification
             object:moviePlayer];

     [moviePlayer setFullscreen:YES animated:YES];
}


- (void)moviePlayBackDidFinish:(NSNotification *)notification {

moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter]
 removeObserver:self
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:moviePlayer];
// If the moviePlayer.view was added to full screen, it needs to be removed

moviePlayer.fullscreen = NO;

}