我已经在ViewController中添加了此代码。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
if (interfaceOrientation != UIInterfaceOrientationPortrait) {
    [self.moviePlayerController setFullscreen:YES animated:YES];
}
return YES;
}

因此,旋转后,我的播放器将以全屏模式播放视频。我需要在playerController(OrientationPortrait)中捕获旋转事件以将setFullScreen:NO。
我怎样才能做到这一点?
感谢您的回答。

最佳答案

moviePlayerController的方向设置不应在此函数中处理。

在viewWillAppear函数中添加通知程序

-(void)viewWillAppear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(orientationChanged:)  name:UIDeviceOrientationDidChangeNotification  object:nil];}

方向变化通知此功能
- (void)orientationChanged:(NSNotification *)notification{
[self adjustViewsForOrientation:[[UIApplication sharedApplication] statusBarOrientation]];}

依次调用此函数(在moviePlayerController框架方向上)
- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation {

if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
    [self.moviePlayerController setFullscreen:NO animated:YES];
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
    [self.moviePlayerController setFullscreen:YES animated:YES];
}}

在viewDidDisappear中删除通知
-(void)viewDidDisappear:(BOOL)animated{
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];}

10-06 05:06