我在捕获 YouTube 播放器在 iOS 8 中进入全屏或退出全屏时遇到问题,因为这些通知已被删除UIMoviePlayerControllerDidEnterFullscreenNotification
and UIMoviePlayerControllerWillExitFullscreenNotification
对于此版本的操作系统版本。
因为我的应用程序项目设置为仅在纵向模式下,所以视频在播放时不会旋转到横向模式,这在设备上观看视频时确实不太用户友好。
通常,当视频进入全屏时,用户希望以纵向模式或横向模式观看视频。
这就是我这样做的方式iOS 7可以完美运行,但在 iOS 8 中不行。
首先,我将在我的AppDelegate.m
我的布尔属性AppDelegate.h
我称之为videoIsInFullscreen
和功能,
// this in the AppDelegate.h
@property (nonatomic) BOOL videoIsInFullscreen;
// This in my AppDelegate.m to allow landscape mode when the boolean property is set to yes/true.
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
if(self.videoIsInFullscreen == YES)
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else
{
return UIInterfaceOrientationMaskPortrait;
}
}
然后在我的ViewController.m
首先,我会#import "AppDelegate.h"
完成此操作后,我将在我的中添加一些通知viewDidLoad
方法..
-(void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerStarted) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerEnded) name:@"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];
}
当然别忘了删除它们..
-(void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];
}
然后,我的功能将在这些通知触发时被调用...这是我允许横向模式然后将其设置回纵向的地方。我的应用程序就是这种情况,因为它仅设置为纵向支持,但我不希望在 YouTube 视频中使用此功能。
// first we set our property in the our AppDelegate to YES to allow landscape mode
- (void)playerStarted
{
((AppDelegate*)[[UIApplication sharedApplication] delegate]).videoIsInFullscreen = YES;
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
}
// Then I will set the property to NO and force the orientation to rotate to portrait.
- (void)playerEnded
{
((AppDelegate*)[[UIApplication sharedApplication] delegate]).videoIsInFullscreen = NO;
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
}
但是,iOS 8 的情况并非如此。这些通知不再适用于 iOS 8,因此,我使用这些通知发现了类似的内容,但我不太高兴,因为它们对于视频播放器来说并不是 100% 准确。UIWindowDidBecomeVisibleNotification
and UIWindowDidBecomeHiddenNotification
那么,我怎样才能正确地做到这一点,或者至少对我的 YouTube 嵌入视频正常工作并允许 iOS 8 中的横向模式......?