Allow video on landscape with only-portrait app

前端 未结 8 1391
没有蜡笔的小新
没有蜡笔的小新 2020-12-13 06:35

I have a UIWebView included in a UIViewController which is a descendant of UINavigationController. It looks like this:

8条回答
  •  失恋的感觉
    2020-12-13 07:18

    Swift version:

    //AppDelegate:
        func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> Int {
    
            var presentedVC = application.keyWindow?.rootViewController
            while let pVC = presentedVC?.presentedViewController
            {
                presentedVC = pVC
            }
            if let pVC = presentedVC
            {
                if contains(["MPInlineVideoFullscreenViewController", "MPMoviePlayerViewController", "AVFullScreenViewController"], pVC.nameOfClass)
                {
                    return Int(UIInterfaceOrientationMask.AllButUpsideDown.rawValue)
                }
            }
    
            return Int(UIInterfaceOrientationMask.Portrait.rawValue)
        }
    
    //Extension:
    public extension NSObject{
        public class var nameOfClass: String{
            return NSStringFromClass(self).componentsSeparatedByString(".").last!
        }
    
        public var nameOfClass: String{
            return NSStringFromClass(self.dynamicType).componentsSeparatedByString(".").last!
        }
    }
    
    //View controller:
        override func supportedInterfaceOrientations() -> Int {
            return Int(UIInterfaceOrientationMask.Portrait.rawValue)
        }
    
        override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
            return UIInterfaceOrientation.Portrait
        }
    
        override func shouldAutorotate() -> Bool {
            return false
        }
    
        override func viewWillLayoutSubviews() {
            UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.None)
        }
    

提交回复
热议问题