仅支持纵向应用程序中的视频播放器视图控制器的所有方向

时间:2016-06-22 09:18:03

标签: ios objective-c mpmovieplayercontroller

我在AppDelegate.m

中实现了这段代码
import { Directive, ElementRef, Input } from '@angular/core';

@Directive({
  selector: '[myHighlight]',
  host: {
    '(mouseenter)': 'onMouseEnter()',
    '(mouseleave)': 'onMouseLeave()'
  }
})
export class HighlightDirective {
  private _defaultColor = 'blue';
  private el: HTMLElement;

  constructor(el: ElementRef) { this.el = el.nativeElement; }

  @Input('myHighlight') highlightColor: string;

  onMouseEnter() { this.highlight(this.highlightColor || this._defaultColor); }
  onMouseLeave() { this.highlight(null); }

   private highlight(color:string) {
    this.el.style.backgroundColor = color;
  }

}

并使用以下链接推送到VideoPlayerVC:

-(UIInterfaceOrientationMask) application:(UIApplication *)application supportedInterfaceOrientationsForWindow :(UIWindow *)window
{
    UIViewController *currentVC = [(UINavigationController *)[UIApplication sharedApplication].delegate.window.rootViewController topViewController];
    if ([currentVC isKindOfClass:[VideoPlayerVC class]])
    {
        return UIInterfaceOrientationMaskAll;
    }

    return UIInterfaceOrientationMaskPortrait;
}

这允许我在VideoPlayer ViewController中启用自动旋转,但当视频播放以横向模式结束时,整个应用程序仅转换为横向视图模式。

请帮我们解决这个问题。 提前谢谢。

1 个答案:

答案 0 :(得分:1)

系统仅在全屏模式演示发生或解除时尝试使您的方向无效。因此,我建议您将[self.navigationController pushViewController:vc animated:false];替换为[self presentViewController:vc animated:YES completion:nil];

如果您的UE需要导航转换,您可以尝试使用UIViewControllerContextTransitioning自定义来模仿它。

如果你必须使用推送行为,那么还有一个棘手的方法(据我所知,这是唯一一种不使用私有api的方法) 每次从导航堆栈中弹出/弹出时,请调用以下代码: [[vc presentViewController:[UIViewController new] animated:NO completion:^(BOOL completed){ [vc dismissViewControllerAnimated:NO completion:nil]; }]; 代码尝试制作一个不可见的vc并立即将其解除,以使iOS更新支持的方向。

相关问题