gpt4 book ai didi

ios - MPMoviePlayerController - 全屏 | swift

转载 作者:行者123 更新时间:2023-11-28 10:24:22 24 4
gpt4 key购买 nike

我目前正在尝试在我的 Swift 应用程序中实现 MPMoviePlayerController。加载视频后(通过单击前一个 View Controller 上的按钮),我希望视频进入全屏模式。使用我当前的代码,这在纵向上完美运行,但一旦视频旋转到横向,它只占屏幕的一半。有什么办法可以解决这个问题吗?

这是我的代码:

 override func viewDidLoad() {
super.viewDidLoad()

var url:NSURL = NSURL(string: "http://jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v")

moviePlayer = MPMoviePlayerController(contentURL: url)
moviePlayer.view.frame = CGRect(x: 20, y: 100, width: 200, height: 150)

self.view.addSubview(moviePlayer.view)
moviePlayer.fullscreen = true

moviePlayer.controlStyle = MPMovieControlStyle.Embedded}

这里有一些屏幕截图可以帮助解释我的意思:

Portrait working great - want it like this for landscape

landscape - cuts off the picture, seems to be trying to fit the portrait view on to the landscape view controller. Weird O_o

最佳答案

View 没有调整大小,因为您的代码从来没有告诉它。

如果您希望它在旋转时调整大小,您需要在容器 View 因旋转而改变时调整 MPMoviePlayerController 的 View 大小。 (在 viewWillLayoutSubviews 中设置框架或使用自动布局将 MPMoviePlayerController 的 View 限制为呈现 Controller 的 View 。)

您也可以使用 MPMoviePlayerViewController 代替 MPMoviePlayerController。来自文档:

Unlike using an MPMoviePlayerController object on its own to present a movie immediately, you can incorporate a movie player view controller wherever you would normally use a view controller.

你可以这样使用它:

class MainViewController : UIViewController {
var movieViewController : MPMoviePlayerViewController?

override func viewDidLoad() {
var url = NSURL(string: "http://jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v")!
movieViewController = MPMoviePlayerViewController(contentURL: url)
movieViewController?.moviePlayer.fullscreen = true
movieViewController?.moviePlayer.controlStyle = .Embedded
}

override func viewDidAppear(animated: Bool) {
self.presentMoviePlayerViewControllerAnimated(movieViewController)
}
}

关于ios - MPMoviePlayerController - 全屏 | swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29722277/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com