2016-02-29 45 views
1

我有一个UIView实际上是YTPlayerViewyoutube-ios-sdk如何使UIView全屏当用户将其设备从纵向旋转到横向模式时

当设备向左或向右旋转时,当设备旋转回肖像模式(如官方YouTube应用程序中)时,我需要将其设为全屏模式并将其恢复为非全屏模式。

我该如何实现这样的行为?

我在YTPlayerView的界面上看不到任何setFullScreenMode函数。

+0

你有没有尝试过的视图的框架设置为UIScreen的帧大小?不知道它是否会工作 – hola

回答

0

确保您试图在设备旋转时修改视图的框架?

这是我做的:

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator { 
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; 

    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) 
    { 

    } completion:^(id<UIViewControllerTransitionCoordinatorContext> context) 
    { 
     UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; 
     switch (orientation) { 
      case UIInterfaceOrientationPortrait: 

       break; 
      case UIInterfaceOrientationLandscapeLeft: 
      case UIInterfaceOrientationLandscapeRight: 
       [self.testView setFrame:CGRectMake(0, 0, size.width, size.height)]; 
       break; 
      default: 
       break; 
     } 
    }]; 
} 
+0

感谢您的答案,但不幸的是它不工作 - 'YTPlayerView'仍然有相同的大小(屏幕的一半) – FrozenHeart

+0

看来,另一个视图阻止它(可能是因为布局约束) - http://i.imgur.com/GRn2MCz.png。我能做什么? – FrozenHeart

+0

我在这两个设备和模拟器上都成功了。 (YTPlayerView当然有布局约束)。 你是否实现了supportedInterfaceOrientations和shouldAutorotate? 这是一个简单的视频。 https://www.youtube.com/watch?v=lyjD4V-kGOQ&feature=youtu.be –

0

请确保您的设备可以能够旋转显示器(人像方向锁定应关闭)。

+0

我在模拟器上测试我的应用程序,所以是的,它可以旋转显示 – FrozenHeart

0

这为我工作,在Xcode 9.2和迅速的4

var videoView: UIView! 
var playerLayer: AVPlayerLayer! 

if UIDeviceOrientationIsLandscape(UIDevice.current.orientation){ 
     let screenSize = UIScreen.main.bounds 
     let screenWidth = screenSize.width 
     let screenHeight = screenSize.height 
     videoView.frame = CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight) 
     playerLayer.frame = videoView.bounds 
    } 
相关问题