1

我有一个UIView实际上YTPlayerView来自youtube-ios-sdk

我需要在设备向左或向右旋转时将其设为全屏,并在设备旋转回纵向模式时将其返回到非全屏模式(如在官方 YouTube 应用程序中)。

我怎样才能实现这种行为?

我在的界面中看不到任何setFullScreenMode功能。YTPlayerView

4

3 回答 3

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;
         }
     }];
}
于 2016-02-29T10:36:13.353 回答
0

这对我有用,在 xcode 9.2 和 swift 4

var videoView: UIView!
var playerLayer: AVPlayerLayer!

override func viewDidLayoutSubviews(){
    if UIDeviceOrientationIsLandscape(UIDevice.current.orientation) && !(UIDevice.current.orientation.isFlat) {
        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
    }
}
于 2018-02-20T06:53:05.093 回答
0

确保您的设备能够旋转显示(纵向锁定应关闭)。

于 2016-02-29T11:15:46.273 回答