Ios AVPlayer视图控制器自动旋转关闭?
我只在纵向模式下使用iOS应用程序,它工作正常 问题是我在navigationController(都是通过编程创建的)上面演示了AvPlayServiceWController。这个球员支持所有的旋转(我不知道为什么!) 我只想将此设置为肖像模式,就像应用程序的其他部分一样Ios AVPlayer视图控制器自动旋转关闭?,ios,swift,avplayerviewcontroller,autorotate,Ios,Swift,Avplayerviewcontroller,Autorotate,我只在纵向模式下使用iOS应用程序,它工作正常 问题是我在navigationController(都是通过编程创建的)上面演示了AvPlayServiceWController。这个球员支持所有的旋转(我不知道为什么!) 我只想将此设置为肖像模式,就像应用程序的其他部分一样 我们如何才能做到这一点?创建从AvPlayServiceController继承的新类,并像这样实现受支持的接口方法。在此之后,只需创建您所创建的类的对象,而不是初始化AVPlayerViewController的对象 c
我们如何才能做到这一点?创建从AvPlayServiceController继承的新类,并像这样实现受支持的接口方法。在此之后,只需创建您所创建的类的对象,而不是初始化AVPlayerViewController的对象
class MyPortraitVideoController: AVPlayerViewController {
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
}
编辑以添加:
请注意,缔约国: 重要
不要将AVPlayerViewController子类化。凌驾于此 类的方法不受支持,并导致未定义的行为
由于这是公认的答案,我认为OP已经尝试过了,并且成功了,但是我认为我应该在这里添加一个关于它的注释,以确保未来的读者知道任何潜在的问题。未定义的行为意味着这可能在未来的iOS版本中停止工作。在我的情况下,我必须限制某些视图的横向方向。因此我在AppDelegate中将支持的界面方向设置为纵向。当我演示AVPlayerViewController时,我必须在AppDelegate中将支持的接口方向设置为所有。 同时检查以下代码 AppDelegate.swift
var shouldSupportLandscape = Bool()
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if self.shouldSupportLandscape == true {
return .all
}else {
return .portrait
}
}
当存在AVPlayerViewController时
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.shouldSupportLandscape = true
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.shouldSupportLandscape = false
当关闭AVPlayerViewController时
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.shouldSupportLandscape = true
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.shouldSupportLandscape = false
是的,我刚试过这个,正要把答案贴出来。谢谢:)那我也得投你一票了。”因为你已经得到了答案,没有任何人的帮助。似乎是正确的答案,除了这个:。“重要提示:不要将avplayervewcontroller作为子类。重写此类的方法不受支持,并且会导致未定义的行为。”@JeffLoughlin,感谢您的评论。在这个场景中,您知道如何解决这个问题(不使用子类)吗?