gpt4 book ai didi

ios - 在全屏模式下强制横向显示 MPMoviePlayerController 会在退出全屏模式时阻止正确的旋转

转载 作者:技术小花猫 更新时间:2023-10-29 10:16:12 25 4
gpt4 key购买 nike

我有一个支持所有界面方向的 iPhone 应用程序 (iOS6+)。但是,当 MPMoviePlayerController 全屏播放视频时,只应支持横向。

我在 Stack Overflow 上找到了以下解决方案并且它有效。

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];

...

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (self.landscapeOnlyOrientation) {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
return UIInterfaceOrientationMaskAll;
}

- (void)moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
self.landscapeOnlyOrientation = YES;
}

- (void)moviePlayerWillExitFullscreenNotification:(NSNotification*)notification {
self.landscapeOnlyOrientation = NO;
}

但是,一个烦人的问题仍然存在,即如果视频以纵向退出全屏(在强制横向播放后),底层 View 不会旋转回来。我必须手动将设备旋转到横向并返回纵向以触发方向更新。有什么方法可以以编程方式触发这种更新吗?

下面的一组截图应该可以说明我的意思:

enter image description here enter image description here enter image description here

注意:由于各种原因,无法使用 MPMoviePlayerViewController。

最佳答案

大家好,我遇到了同样的问题,我已经解决了-

这是我的完整代码....

您需要先在 appdelegate 中进行更改:

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([[[NowPlaying sharedManager] playerViewController] allowRotation])//Place your condition here
{
return UIInterfaceOrientationMaskAll;
}
return UIInterfaceOrientationMaskPortrait;
}

为全屏控制注册通知:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:)
name:MPMoviePlayerWillEnterFullscreenNotification
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:)
name:MPMoviePlayerWillExitFullscreenNotification
object:nil];

然后在播放器 Controller 中添加一行代码:

- (void)moviePlayerWillEnterFullscreenNotification:(NSNotification *)notification
{
dispatch_async(dispatch_get_main_queue(), ^
{
self.allowRotation = YES;
});
}



- (void)moviePlayerWillExitFullscreenNotification:(NSNotification *)notification
{
self.allowRotation = NO;
[self.moviePlayerController setControlStyle:MPMovieControlStyleNone];

dispatch_async(dispatch_get_main_queue(), ^
{

//Managing GUI in pause condition
if (self.currentContent.contentType == TypeVideo && self.moviePlayerController.playbackState == MPMoviePlaybackStatePaused)
{
[self.moviePlayerController pause];
if (self.playButton.selected)
self.playButton.selected = NO;
}
self.view.transform = CGAffineTransformMakeRotation(0);
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
self.view.bounds = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
});
}

此代码在 iOS6 和 iOS7 中测试工作正常。谢谢:)

如果有任何问题,请告诉我......

关于ios - 在全屏模式下强制横向显示 MPMoviePlayerController 会在退出全屏模式时阻止正确的旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21911151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com