简体   繁体   English

当非全屏时,如何获取MPMoviePlayerController的视图以在旋转时调整大小

[英]How to get MPMoviePlayerController's view to resize on rotate when it is not full-screen

Our client wants to display a video in a view on the screen. 我们的客户想要在屏幕上的视图中显示视频。 The code creates an MPMoviePlayerController and installs it's view as a subview of it's container view, just like the docs say to do: 该代码创建一个MPMoviePlayerController并将其视图安装为其容器视图的子视图,就像文档中说的那样:

  moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: myVideoURL];
  [moviePlayer prepareToPlay];
  [moviePlayer.view setFrame: _videoPlaybackContainerView.bounds];

  moviePlayer.controlStyle = MPMovieControlStyleNone;
  [_videoPlaybackContainerView addSubview: moviePlayer.view];

I have the container view set up to resize when the view controller's content view resizes due to auto-rotation. 当视图控制器的内容视图由于自动旋转而调整大小时,我将容器视图设置为调整大小。

If I rotate the device while the video is playing you can see that the container view resizes, but the video does not. 如果我在播放视频时旋转设备,可以看到容器视图的大小已调整,但视频没有调整。 It gets clipped, doesn't center in the view, etc. 它被裁剪,不在视图中居中,等等。

I guess I could try to set up the resizing masks on the player's view (we're not using AutoLayout for this project) but the docs do say to treat the player's view as an opaque structure, and I'm not sure if mucking with it's resize masks violates that or not. 我想我可以尝试在播放器的视图上设置调整大小的蒙版(我们不在此项目中使用AutoLayout),但是文档确实说过将播放器的视图视为不透明结构,并且我不确定是否与它的大小调整蒙版是否违反该要求。

I did a fair amount of searching for help on the net, but all the other discussions I could find either dealt with the movie player view CONTROLLER (a different animal) or with full-screen display, which is also different. 我在网络上进行了大量的搜索以寻求帮助,但是我能找到的所有其他讨论都涉及电影播放器​​视图CONTROLLER(一种不同的动物)或全屏显示,这也有所不同。

I've solved it. 我已经解决了

I set the fill mode to aspect fit: 我将填充模式设置为适合方面:

moviePlayer.scalingMode = MPMovieScalingModeAspectFit moviePlayer.scalingMode = MPMovieScalingModeAspectFit

Then when I get a didRotateFromInterfaceOrientation call in my view controller, I resize my container view and simply change the frame of the movie player's view explicitly. 然后,当我在视图控制器中收到didRotateFromInterfaceOrientation调用时,我将调整容器视图的大小,并简单地显式更改电影播放器​​视图的框架。

I had to do some fairly gnarly math to get my video container view to resize to the largest size that exactly preserves the aspect ratio though. 我不得不做一些相当粗糙的数学运算,以使我的视频容器视图调整为最大尺寸,以完全保留宽高比。 That probably would have been straightforward if we were using AutoLayout. 如果我们使用的是AutoLayout,那可能会很简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 SwiftUI 中全屏显示视图? - How to present a view full-screen in SwiftUI? swift-当设备旋转到横向(iPhone / iPad)时,如何使UIView变为全屏? - swift - How to have the UIView turn into full-screen when device rotate to landscape (iPhone/iPad)? MPMoviePlayerController不会在iOS 5中以全屏模式更改方向 - MPMoviePlayerController does not change Orientation in full-Screen mode in iOS 5 自动调整遮罩和全屏视图 - Autoresizing mask and full-screen view 如何在不在全屏UITableView的UIEdgeInsets中的屏幕上通过点击手势: - How to pass tap gesture through point on screen that is not in full-screen UITableView's UIEdgeInsets: 使用 Xcode 11 时,SwiftUI 视图以小 window 而不是全屏呈现 - SwiftUI view being rendered in small window instead of full-screen when using Xcode 11 如何在动作表中呈现动作扩展而不是全屏模态视图? - How to present an action extension in an action sheet rather than full-screen modal view? 如何使用xcode的界面生成器设计多个全屏原型单元? - How to design multiple full-screen prototype cells using xcode's interface builder? 使用UIImagePickerController拍摄视频和picker'view不能全屏显示吗? - Using UIImagePickerController to take video and picker'view not full-screen? 检查视图是在Popover还是全屏显示 - Check whether View is shown in Popover or in full-screen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM