Iphone 在UIWebView视频播放期间允许UIInterfaceOrientationAndscape
我的iPhone应用程序是一个仅面向纵向的应用程序,在我的应用程序中,我有一个Iphone 在UIWebView视频播放期间允许UIInterfaceOrientationAndscape,iphone,objective-c,uiwebview,Iphone,Objective C,Uiwebview,我的iPhone应用程序是一个仅面向纵向的应用程序,在我的应用程序中,我有一个UITableView,在第一个UITableCell中有一个UIWebView。UIWebView显示一个嵌入式youtube视频。当我点击视频播放时,它进入全屏模式。我需要做的是,允许用户旋转设备并以横向模式播放视频。然后,当视频停止时,只允许再次拍摄肖像。我设置为在视频进入全屏和离开全屏时收听通知。但我不知道如何通过编程允许用户旋转界面方向 所以基本上我有两个方法在通知传递时调用 [[NSNotification
UITableView
,在第一个UITableCell
中有一个UIWebView
。UIWebView
显示一个嵌入式youtube视频。当我点击视频播放时,它进入全屏模式。我需要做的是,允许用户旋转设备并以横向模式播放视频。然后,当视频停止时,只允许再次拍摄肖像。我设置为在视频进入全屏和离开全屏时收听通知。但我不知道如何通过编程允许用户旋转界面方向
所以基本上我有两个方法在通知传递时调用
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeFinished:) name:@"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];
-(void)youTubeStarted:(NSNotification *)notification{
// Entered fullscreen code goes here.
}
-(void)youTubeFinished:(NSNotification *)notification{
// Left fullscreen code goes here.
}
我会在这两种方法中添加什么,以允许仅在视频播放期间更改方向?您会有一个全局状态变量,可能在您的应用程序委托中,或者在您存储变量的任何位置,这些变量应该是全局可访问的,然后根据电影播放器是否全屏,将其设置为
true
或false
。在为旋转应用程序而调用的回调中,您检查变量的状态,并根据该返回检查是否允许旋转。我找到了答案。在我的两种方法中:
-(void)youTubeStarted:(NSNotification *)notification{
// Entered Fullscreen code goes here..
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.fullScreenVideoIsPlaying = YES;
}
-(void)youTubeFinished:(NSNotification *)notification{
// Left fullscreen code goes here...
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.fullScreenVideoIsPlaying = NO;
//CODE BELOW FORCES APP BACK TO PORTRAIT ORIENTATION ONCE YOU LEAVE VIDEO.
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
//present/dismiss viewcontroller in order to activate rotating.
UIViewController *mVC = [[UIViewController alloc] init];
[self presentModalViewController:mVC animated:NO];
[self dismissModalViewControllerAnimated:NO];
}
通过设置我的AppDelegate的BOOL属性,我在上述方法中访问了我的AppDelegate。然后我在AppDelegate.m中调用了下面的应用程序方法:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
NSUInteger orientations = UIInterfaceOrientationMaskPortrait;
if (self.fullScreenVideoIsPlaying == YES) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else {
if(self.window.rootViewController){
UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
orientations = [presentedViewController supportedInterfaceOrientations];
}
return orientations;
}
}
self.fullScreenVideoIsPlaying
是我在AppDelegate.h文件中设置为属性的BOOL
我希望这能帮助其他人度过我失去的5个小时。如果你只想支持全屏横向播放。从iOS 8开始,来自
UIWebView
的视频在avplayervewcontroller
内部播放
在AppDelegate中,检查演示窗口是否包含avplayervewcontroller
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if let w = window, let root = w.rootViewController {
if root.childViewControllers.first is AVPlayerViewController {
return UIInterfaceOrientationMask.allButUpsideDown
}
}
return UIInterfaceOrientationMask.portrait
}
我可能应该提到,出于这个确切的原因,我也有一个BOOL设置,但我未能尝试在回拨中更改是否允许旋转以旋转应用程序。你能给我看一些允许的代码吗?谢谢!!我花了几个小时寻找这个问题的答案,而你的解决方案是迄今为止最简单的。非常感谢:)我一直在寻找几个小时如何解决我的旋转问题。这就解决了它;然而,我似乎无法让它在视频结束后禁用旋转。你把你的通知电话放在哪里了?没关系,我把它修好了。我意识到我的整个应用程序都在旋转。为了解决这个问题,我刚刚删除了SupportedInterfaceOrientionsForWindow方法中的if(self.window.rootViewController)语句。现在一切都很好。谢谢你发布这个!Hi@BrowneFace删除后,我也无法停止应用程序中的定向。而且在完成视频应用程序后,仍然只处于风景模式。它不会强有力地改变。请帮帮我,我做错了什么,我如何启动这两种方法?在触动WebView时向其添加目标?请小心,因为IOS6“视频完成按钮”的通知似乎是:
UIMoviePlayerController illexitFullScreenNotification
(请参阅:和)可能重复的