swift - Landscape orientation View Controller App Delegate -


i'm trying put view controller in landscape mode , other ones in portrait mode.

first of all, i've tried invalidate rotation of each view controller except 1 want (with shouldautorotate false, portrait, ...), navigation controller have, overlaps nav bar status bar, , couldn't solve it. after that, i've tried clean i've done , enable or disable orientation appdelegate.

so here's code found , tried:

    func application(application: uiapplication, supportedinterfaceorientationsforwindow window: uiwindow?) -> int {          if self.window?.rootviewcontroller?.presentedviewcontroller secondviewcontroller {              let secondcontroller = self.window!.rootviewcontroller!.presentedviewcontroller as! secondviewcontroller              if secondcontroller.ispresented {                 return int(uiinterfaceorientationmask.all.rawvalue);             } else {                 return int(uiinterfaceorientationmask.portrait.rawvalue);             }         } else {             return int(uiinterfaceorientationmask.portrait.rawvalue);         }      } 

but code never goes in first if (even if view controller secondviewcontroller).

so idea of how can check if i'm in specific vc can specify orientation?

thanks in advance!

checkout recursive method getting current viewcontroller

func getcurrentviewcontroller(viewcontroller:uiviewcontroller?)-> uiviewcontroller?{      if let tabbarcontroller = viewcontroller as? uitabbarcontroller{          return getcurrentviewcontroller(tabbarcontroller.selectedviewcontroller)     }      if let navigationcontroller = viewcontroller as? uinavigationcontroller{         return getcurrentviewcontroller(navigationcontroller.visibleviewcontroller)     }      if let viewcontroller = viewcontroller?.presentedviewcontroller {          return getcurrentviewcontroller(viewcontroller)      }else{          return viewcontroller     } } 

and use on supported orientation method follow

func application(application: uiapplication, supportedinterfaceorientationsforwindow window: uiwindow?) -> int {      if let currentvc = getcurrentviewcontroller(self.window?.rootviewcontroller) as? secondviewcontroller{              return int(uiinterfaceorientationmask.all.rawvalue)      }     return int(uiinterfaceorientationmask.portrait.rawvalue) } 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -