【发布时间】:2017-10-09 11:50:56
【问题描述】:
目前,当按下 AVPlayer 全屏按钮时,我正在强制更改方向。我尝试了类似的操作
final class NewMoviePlayerViewController: AVPlayerViewController {
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if contentOverlayView?.bounds == UIScreen.main.bounds{
DispatchQueue.main.async {
let value = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
}
print("full screen")
}else{
DispatchQueue.main.async {
let value = UIInterfaceOrientation.portrait.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
}
print("half screen")
}
}
}
以上代码在 iOS 11 中运行良好,但相同代码在 iOS 10 及以下版本中无法运行
【问题讨论】:
-
contentOverlayView?.bounds == UIScreen.main.bounds在 iOS 10(及更低版本)中为真,或者问题在UIDevice.current.setValue(value, forKey: "orientation")内部? -
@AlbertoCantallops 条件进入但强制方向代码不起作用
-
看看stackoverflow.com/questions/26357162/… 有很多不同的方法。请注意,接受的答案是您如何做到的,但stackoverflow.com/a/28220616/7064692 可能会有所帮助
-
感谢回复,已完成
标签: ios swift avplayerviewcontroller