2016-09-05 27 views
5

çağrılmayı durduruyor. 1 veya 2 UIView denetleyicisini Landscape modundayken Portre modundayken diğerlerini göstermek istiyorum. Bu amaçla, bu işlevi AppDelegate uygulamasında uygulamış oldum. I Yatay yönlendirme mi UIViewController'ın (ler) olarakiOS9 supportedInterfaceOrientationsForWindow,

@property (nonatomic, assign) UIInterfaceOrientationMask orientation; 

: AppDelegate.h içinde yönlendirmedeyken

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

. Ben, bu kodu

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

ve

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

Ancak, ben 'LandscapeViewController' ok çalışır giderken, geri dönmek, o, tekrar onun ok 'LandscapeViewController' gidin Tamam çalışan

yerleştirmek ve sonra geri döndüğümde, desteklenenInterfaceOrientationsForWindow yöntemi çağrılmayı durdurur. Bunun bir sebebi var mı? ya da garip bir şey yapıyorum?

cevap

3

Eğer UITabBarController UITabBarController için özel bir sınıf oluşturmak ve orada

-(UIInterfaceOrientationMask) supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 

bu kodu yerleştirebilirsiniz ve ihtiyaca göre görünümünüzü denetleyicileri bu koyun kullanıyorsanız.

yer bu

-(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; 
} 

appDelegate

kod ve

-(void)canRotate 
{ 

} 
+0

evet ben tabbar kullanıyorum görünümünüzü denetleyicisi bu yerleştirin. – Haris