avfoundation - iOS: AVPlayerViewController enable fullscreen rotation in portrait oriented application -
i have uiviewcontroller, contains avplayerviewcontroller avplayer. want enable rotation avplayerviewcontroller(when video on fullscreen) , disable rotation uiviewcontroller. how can enable rotation videos(on fullscreen) in app?
swift 2.2 in appdelegate allow rotation player:
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 }
than create , use subclass of avplayerviewcontroller portrait mode when player exit full screen mode:
class yourvideoplayer: avplayerviewcontroller { override func viewdidlayoutsubviews() { super.viewdidlayoutsubviews() if view.bounds == contentoverlayview?.bounds { uidevice.currentdevice().setvalue(uiinterfaceorientation.portrait.rawvalue, forkey: "orientation") } }
Comments
Post a Comment