2016-09-05 2 views
5

Ich möchte 1 oder 2 UIViewcontrollers im Querformatmodus zeigen, während andere im Hochformat angezeigt werden. Zu diesem Zweck habe ich diese Funktion in AppDelegate implementiert.iOS9 supportedInterfaceOrientationsForWindow hört auf, angerufen zu werden

-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
    return self.orientation; 
} 

wo in AppDelegate.h, Orientierung ist:

@property (nonatomic, assign) UIInterfaceOrientationMask orientation; 

In Uiviewcontroller (n), wo ich Querformat benötigen. Ich stelle diesen Code

-(void)viewWillAppear:(BOOL)animated 
{ 
    self.appDelegate.orientation = UIInterfaceOrientationMaskLandscape; 
} 

und

-(void)viewWillDisappear:(BOOL)animated 
{ 
    self.appDelegate.orientation = UIInterfaceOrientationMaskPortrait; 
} 

Allerdings, wenn ich zu 'LandscapeViewController' gehe es funktioniert ok, gehe ich zurück, es funktioniert ok, ich gehe wieder zu 'LandscapeViewController' its ok, und wenn ich zurückkomme, wird die Methode supportInterfaceOrientationsForWindow nicht mehr aufgerufen. Irgendein Grund dafür? oder mache ich etwas komisches?

Antwort

3

Wenn Sie mit UITabBarController eine benutzerdefinierte Klasse für UITabBarController erstellen und diesen Code dort

-(UIInterfaceOrientationMask) supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 

und legen Sie diese in Ihrer Ansicht-Controller nach Ihrem Bedarf.

Ort dieser Code in AppDelegate

-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 

    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; 

    id rootViewController = [self topViewControllerWithRootViewController:window.rootViewController]; 

    if (rootViewController != nil) 
    { 
     if ([rootViewController respondsToSelector:@selector(canRotate)]) 
     { 
      return UIInterfaceOrientationMaskLandscape; 
     } 
    } 
    return UIInterfaceOrientationMaskPortrait; 
} 

-(UIViewController*) topViewControllerWithRootViewController:(id)rootViewController 
{ 

    if (rootViewController == nil) 
    { 
     return nil; 
    } 

    if ([rootViewController isKindOfClass:[UITabBarController class]]) 
    { 
     UITabBarController *selectedTabBarController = rootViewController; 
     return [self topViewControllerWithRootViewController:selectedTabBarController.selectedViewController]; 
    } 
    else if ([rootViewController isKindOfClass:[UINavigationController class]]) 
    { 
     UINavigationController *selectedNavController = rootViewController; 
     return [self topViewControllerWithRootViewController:selectedNavController.visibleViewController]; 
    } 
    else 
    { 
     UIViewController *selectedViewController = rootViewController; 
     if (selectedViewController.presentedViewController != nil) 
     { 
      return [self topViewControllerWithRootViewController:selectedViewController.presentedViewController]; 
     } 
    } 
    return rootViewController; 
} 

und legen Sie diese in Ihrem View-Controller

-(void)canRotate 
{ 

} 
+0

ja ich Tabbar verwende. – Haris

Verwandte Themen