ton*_*252 13 fullscreen avfoundation ios avplayer avplayerviewcontroller
我有一个UIViewcontroller,它包含一个带AVPlayer的AVPlayerViewController.我想为AVPlayerViewController启用旋转(当视频在全屏时)并禁用UIViewController的任何旋转.如何在我的应用中为视频(全屏)启用旋转?
Сер*_*лык 13
Swift 2.2 在AppDelegate中允许玩家轮换:
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
guard let vc = (window?.rootViewController?.presentedViewController) else {
return .Portrait
}
if (vc.isKindOfClass(NSClassFromString("AVFullScreenViewController")!)) {
return .AllButUpsideDown
}
return .Portrait
}
Run Code Online (Sandbox Code Playgroud)
当播放器退出全屏模式时,创建并使用AVPlayerViewController的子类返回纵向模式:
class YourVideoPlayer: AVPlayerViewController {
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if view.bounds == contentOverlayView?.bounds {
UIDevice.currentDevice().setValue(UIInterfaceOrientation.Portrait.rawValue, forKey: "orientation")
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5615 次 |
| 最近记录: |