【问题标题】:MPInlineVideoFullscreenViewController and AVFullScreenViewController first time comes in portrait modeMPInlineVideoFullscreenViewController 和 AVFullScreenViewController 第一次进入纵向模式
【发布时间】:2015-01-05 14:01:38
【问题描述】:

在 MPMovieplayer 中有太多与横向问题相关的问题。我的应用程序处于纵向模式。但我想要横向模式的视频。我已经有视频的横向/纵向功能。我正在使用以下代码:

static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS7 = @"MPInlineVideoFullscreenViewController";
static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS8 = @"AVFullScreenViewController";

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
  if ([[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS7)] ||
    [[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS8)]) 
{

    return UIInterfaceOrientationMaskAllButUpsideDown;
}
else {
    return UIInterfaceOrientationMaskPortrait;
}

}

代码在 iOS 7 和 iOS8 中都可以正常工作。 但问题是,当设备处于横向模式时,视频首先以纵向模式打开。改变方向后,应用可以正常工作。

提前致谢。

【问题讨论】:

  • 有什么方法可以手动调用以下方法:- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 或任何其他方式手动更新 mpmovieplayer 的方向。所以它会解决我的问题。
  • 你能试试下面的代码吗,[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO]; [[自拍] setBounds:CGRectMake(0, 0, 480, 320)]; [[自拍] setCenter:CGPointMake(160, 240)]; [[自拍] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];播放视频时放置上面的代码。以上代码适用于 iPhone 4 屏幕尺寸,请根据您的设备屏幕尺寸更改值。
  • @sundeep 我在触发视频开始通知时将上述代码添加到该方法中。但运气不好,它在我的最后不起作用。视频屏幕不旋转。

标签: ios ios8 mpmovieplayercontroller mpmovieplayer xcode6.1


【解决方案1】:

经过长时间的研发和不同的方法和花费 2-3 天。最后我在朋友的帮助下得到了答案。如果我们的视图控制器处于纵向模式,则以下代码无法推送玩家视图风景。

static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS7 = @"MPInlineVideoFullscreenViewController";
static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS8 = @"AVFullScreenViewController";

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
  if ([[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS7)] ||
[[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS8)]) 
{
  return UIInterfaceOrientationMaskAllButUpsideDown;
}
else {
return UIInterfaceOrientationMaskPortrait;

}

在我的情况下,问题是我的 UIWebView 容器视图控制器非常有时间进入纵向模式。我不知道在 UINavigationController 中推送 ViewController 之后,该 ViewController 不调用方向方法。

-(BOOL)shouldAutorotate;  
-(NSUInteger)supportedInterfaceOrientations;

为了解决这个问题,我将在 ViewDidLoad 方法中添加以下代码

NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];

并且在 viewWillDisappear 中的以下代码中

NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];

上面的代码终于解决了我的问题。

感谢所有支持我解决此问题的人。

【讨论】:

  • @tomDev 您可以通过将方法名称替换为以下内容来修复警告:- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:( UIWindow *)window
  • 有人找到在 Swift 上实现这个的方法吗?
  • iOS9和iOS10怎么样?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多